MATLAB The first steps. Edited by Péter Vass

Similar documents
General Information. There are certain MATLAB features you should be aware of before you begin working with MATLAB.

An Introduction to MATLAB See Chapter 1 of Gilat

Starting MATLAB To logon onto a Temple workstation at the Tech Center, follow the directions below.

2.0 MATLAB Fundamentals

Chapter 1: An Overview of MATLAB

PROGRAMMING WITH MATLAB DR. AHMET AKBULUT

Dr Richard Greenaway

Outline. CSE 1570 Interacting with MATLAB. Outline. Starting MATLAB. MATLAB Windows. MATLAB Desktop Window. Instructor: Aijun An.

Outline. CSE 1570 Interacting with MATLAB. Starting MATLAB. Outline (Cont d) MATLAB Windows. MATLAB Desktop Window. Instructor: Aijun An

Introduction to MATLAB

Introduction to Engineering gii

General MATLAB Information 1

Computer Programming in MATLAB

Outline. CSE 1570 Interacting with MATLAB. Starting MATLAB. Outline. MATLAB Windows. MATLAB Desktop Window. Instructor: Aijun An.

Variables are used to store data (numbers, letters, etc) in MATLAB. There are a few rules that must be followed when creating variables in MATLAB:

MATLAB. Miran H. S. Mohammed. Lecture 1

MATLAB Project: Getting Started with MATLAB

ENGR 1181 MATLAB 05: Input and Output

Chapter 1 Introduction to MATLAB

SECTION 1: INTRODUCTION. ENGR 112 Introduction to Engineering Computing

the Enter or Return key. To perform a simple computations type a command and next press the

Edward Neuman Department of Mathematics Southern Illinois University at Carbondale

Welcome to EGR 106 Foundations of Engineering II

VARIABLES Storing numbers:

MATLAB Programming for Numerical Computation Dr. Niket Kaisare Department Of Chemical Engineering Indian Institute of Technology, Madras

Introduction to MATLAB

Starting Matlab. MATLAB Laboratory 09/09/10 Lecture. Command Window. Drives/Directories. Go to.

Getting Started. Chapter 1. How to Get Matlab. 1.1 Before We Begin Matlab to Accompany Lay s Linear Algebra Text

Matlab = Matrix Laboratory. It is designed to be great at handling matrices.

Part #1. A0B17MTB Matlab. Miloslav Čapek Filip Kozák, Viktor Adler, Pavel Valtr

Lecture 1: What is MATLAB?

Introduction to MATLAB

MATLAB Project: Getting Started with MATLAB

AMS 27L LAB #1 Winter 2009

Introduction to Matlab. By: Dr. Maher O. EL-Ghossain

Introduction to MATLAB

MAT 275 Laboratory 1 Introduction to MATLAB

Introduction to Matlab to Accompany Linear Algebra. Douglas Hundley Department of Mathematics and Statistics Whitman College

MATLAB Basics EE107: COMMUNICATION SYSTEMS HUSSAIN ELKOTBY

Why use MATLAB? Mathematcal computations. Used a lot for problem solving. Statistical Analysis (e.g., mean, min) Visualisation (1D-3D)

Introduction to MATLAB

Desktop Command window

INTRODUCTION TO MATLAB, SIMULINK, AND THE COMMUNICATION TOOLBOX

Computer Programming ECIV 2303 Chapter 1 Starting with MATLAB Instructor: Dr. Talal Skaik Islamic University of Gaza Faculty of Engineering

Variable Definition and Statement Suppression You can create your own variables, and assign them values using = >> a = a = 3.

MATLAB BASICS. M Files. Objectives

Introduction to Scientific Computing with Matlab

MATLAB Introduction to MATLAB Programming

YOGYAKARTA STATE UNIVERSITY MATHEMATICS AND NATURAL SCIENCES FACULTY MATHEMATICS EDUCATION STUDY PROGRAM

EGR 111 Introduction to MATLAB

Matlab Programming MET 164 1/24

What is MATLAB? It is a high-level programming language. for numerical computations for symbolic computations for scientific visualizations

Introduction to MATLAB

MATLAB Introductory Course Computer Exercise Session

Finding, Starting and Using Matlab

WHAT IS MATLAB?... 1 STARTING MATLAB & USING THE COMMAND LINE... 1 BASIC ARITHMETIC OPERATIONS... 5 ORDER OF OPERATIONS... 7

CSCI 6906: Fundamentals of Computational Neuroimaging. Thomas P. Trappenberg Dalhousie University

MATLAB Lesson I. Chiara Lelli. October 2, Politecnico di Milano

Matlab Programming Introduction 1 2

Introduction to Scientific and Engineering Computing, BIL108E. Karaman

MAT 343 Laboratory 1 Matrix and Vector Computations in MATLAB

MAT 343 Laboratory 1 Matrix and Vector Computations in MATLAB

Introduction to Scientific Computing with Matlab

Lab of COMP 406. MATLAB: Quick Start. Lab tutor : Gene Yu Zhao Mailbox: or Lab 1: 11th Sep, 2013

ECE Lesson Plan - Class 1 Fall, 2001

Introduction to Matlab. Summer School CEA-EDF-INRIA 2011 of Numerical Analysis

UNIVERSITI TEKNIKAL MALAYSIA MELAKA FAKULTI KEJURUTERAAN ELEKTRONIK DAN KEJURUTERAAN KOMPUTER

QUICKBOOKS PRO 2008 AN INTRODUCTION TO QUICKBOOKS PRO

1 Ctrl + X Cut the selected item. 2 Ctrl + C (or Ctrl + Insert) Copy the selected item. 3 Ctrl + V (or Shift + Insert) Paste the selected item

Introduction to MATLAB. Simon O Keefe Non-Standard Computation Group

4 VISUAL FOXPRO - AN INTRODUCTION

Matlab as a calculator

An Introduction to Matlab5

Numerical Analysis First Term Dr. Selcuk CANKURT

Dr Richard Greenaway

Computer Project: Getting Started with MATLAB

Laboratory 1 Octave Tutorial

An Introduction to MATLAB. Lab tutor : Dennis Yang LIU Lab 1: Sept. 11, 2014

MATLAB Part 1. Introduction

Getting Started with MATLAB

ECON 502 INTRODUCTION TO MATLAB Nov 9, 2007 TA: Murat Koyuncu

ELEMENTARY MATLAB PROGRAMMING

SMS 3515: Scientific Computing Lecture 1: Introduction to Matlab 2014

PEACHTREE COMPLETE 2008 AN INTRODUCTION TO PEACHTREE COMPLETE ACCOUNTING

Chapter 1 Introduction to MATLAB

Standardized Tests: Best Practices for the TI-Nspire CX

McTutorial: A MATLAB Tutorial

LAB 1 General MATLAB Information 1

Windows Computer A to Z Shortcut Key list with PDF

Python Programming Exercises 1

A Brief Introduction to MATLAB

MATLAB Basics. Configure a MATLAB Package 6/7/2017. Stanley Liang, PhD York University. Get a MATLAB Student License on Matworks

Introduction to MATLAB Programming

ME 1020 Engineering Programming with MATLAB. Chapter 1 In-Class Assignment: 1.1, 1.3, 1.13, Topics Covered:

The QuickCalc BASIC User Interface

VISUAL FOXPRO AN INTRODUCTION

MATLAB Tutorial. Primary Author: Shoumik Chatterjee Secondary Author: Dr. Chuan Li

Computer Shortcuts. Files menu options in current program. Edits options in current program Universal Help in almost every Windows program.

Introduction to Matlab

INTRODUCTION... 1 UNDERSTANDING CELLS... 2 CELL CONTENT... 4

Transcription:

MATLAB The first steps Edited by Péter Vass

MATLAB The name MATLAB is derived from the expression MATrix LABoratory. It is used for the identification of a software and a programming language. As a software, it provides an interactive computational and program development environment which supports its own programming language. It is a commercial software (not free and not cheap) and developed by the MathWorks Inc.

The basic features of MATLAB programming language It is a 4GL programming language, an interpreted programming language (the interpreter is built in the software), a domain-specific programming language (it is aimed at solving scientific and engineering problems). It supports the imperative, the structural, the procedural and the object-oriented programming. It has sophisticated data structures. It provides vast number of built-in functions for linear algebra, statistics, Fourier analysis, filtering, optimization, numerical integration and solving ordinary differential equations.

The basic features of MATLAB programming language These functions are collected in packages referred to as toolboxes. It provides built-in graphics for visualizing data, enables the user to create applications with graphical user interface (GUI), and also provides interfaces for programs or functions written in other languages such as C, C++, Java, and FORTRAN.

Matlab Integrated Development Environment (IDE) Launching the MATLAB IDE double-clicking the MATLAB shortcut on the desktop, or find the MATLAB item and click it in the start menu Panels of the MATLAB desktop (in the default layout) Current Folder Command Window Workspace Command History

Matlab Integrated Development Environment (IDE) Current Folder Workspace Command Window Command History

Matlab Integrated Development Environment (IDE) Current Folder allows us to view, open, search for folders and files, and make changes to them. Command Window provides the command prompt (>>) which indicates the position of the command line. The command to be executed must be entered here. The entered command is sent to the interpreter which tries to execute it. If the command is incorrect or some condition is not fulfilled, the interpreter sends an error message which is also displayed in this window.

Matlab Integrated Development Environment (IDE) Command Window Otherwise, it executes the command and the result appears in the window. The commands previously entered and the results are listed in sequence above the command line. Workspace shows some information about the variables previously created and/or read from files. Command History lists the commands previously entered in the Command Window. Any command may be recall from here and rerun in the command line by double-clicking it.

Matlab Integrated Development Environment (IDE) Customizing the environment Home tab Environment section Preferences

Matlab Integrated Development Environment (IDE) Invoking the MATLAB help browser Home tab Resources section Help icon

Matlab Integrated Development Environment (IDE) From the command line Type doc in the command line and press the enter key ( ). >> doc Getting information about a valid function >> help funtion_name >> doc function_name Example: >> help exit >> help quit >> doc clc >> clc Watch the content of the Command History window. >> exit

Matlab Integrated Development Environment (IDE) Searching help entries for all MATLAB commands linked up with a keyword >> lookfor keyword Example: >> lookfor spectrum There are different levels of working with the MATLAB environment: using it as a high-performance, complex calculator by typing and running commands one after another, writing a script which contains a series of commands arranged in suitable control structures, and is stored in a script file, then running it as a single command, writing user-defined functions for specific tasks and calling them in the command line.

Using MATLAB as a calculator In the simplest case, we use only numerical constants in our computation. The symbols used for the notation of basic mathematical operations (operators): + * / ^ To modify the order of operations, use ( ) Example: >> (4 + 2) / 3 The result of an executed command is stored in a special variable named ans (answer). See the content of the Workspace panel. Example: >> ans^2 Note that the value of ans has changed in the Workspace panel.

Using MATLAB as a calculator Other special variables for mathematical symbols: pi Inf i and j 1 (imaginary unit) Nan not a number Examples: >> pi >> -2.5/0 >> (-3) ^ 0.5 >> 2+3j * -(5+6j) >> 0/0

Using MATLAB as a calculator Setting the output format The default output format is the short format which displays numbers with four decimal place values. By means of the format command, the output format may be changed. Some other output format: long format displays 15 digits after the decimal point, bank format rounds numbers to two decimal places (for finantial computation), format short e displays numbers in exponential form with a base of four decimal places and the exponent, format long e displays numbers in exponential form with a base of 15 decimal places and the exponent

Using MATLAB as a calculator Example: >> 3 + 4/3 6^2.3 >> format long >> ans >> format bank >> ans >> format short e >> ans >> format long e >> ans >> format short >> ans

Using MATLAB as a calculator Editing the command line There are some useful keyboard shortcut for editing the command line such as: Esc Ctrl Ctrl recalls the previous command recalls the next command clears the command line moves the cursor one character backward moves the cursor one character forward moves the cursor one word to the left moves the cursor one word to the right

Using MATLAB as a calculator Editing the command line Home, End, Del and Backspace keys may also be used with their well-known functions. Variables In order to perform more complex computations, we must apply variables in our commands. A variable is a storage location in the memory which serves for keeping the value of some data, and it has an individual name. We can assign a value to it, and use its value in expressions. A variable has three main properties: its name, its type, and its value.

Using MATLAB as a calculator Variable assignment variable_name = value or expression Expression is a combination of different elements. It may contain: constants, variables, operators (symbols for the operations), and function calls. Examples >>x = 5 See the content of the Workspace panel. >>x = x + 2 >>y = 2*x sin(pi/4) sin() is a built-in function for implementing the mathematical sine function in MATLAB >>help sin

Using MATLAB as a calculator An important rule The variable assignment always has to precede the first use of the variable in a computation. So, a variable without any value cannot be used in an expression. Example >>x = 3 >>x = x + z Since the variable z has not a definite value, the expression in the last command is wrong. MATLAB cannot execute it and we get an error message.

Using MATLAB as a calculator Semicolon in MATLAB It may used at the end of the commands. If we use it, MATLAB will not display the output of the executed command. Example >>x = 3; >>y = x + 5 Multiple variable assignments It is possible to perform more than one variable assignment in the same command line in the following way: >> x = 3.4; y = 7.2; z = x * y

Using MATLAB as a calculator Naming rules of variables a variable name may contain only letters, numbers and underscore characters, the first character must be a letter, since MATLAB is case-sensitive, the capital and small forms of a letter are differentiated, although there is no limit for the length of a variable name, still only a limited number of characters from the beginning are taken into account (run the function namelengthmax). Example >>varname=5; >>VarName=8; >>varname+varname >>namelengthmax

Using MATLAB as a calculator Variable types MATLAB automatically determines the type of a variable whenever we assign a value or expression to it. So, we need not declare the type of any variable unlike other programming languages such as C, Pascal, Fortran, Java etc. Clear command The variables we have created during a MATLAB session are stored in the memory of the computer. It may be necessary to free some memory by erasing useless variables. Erasing variable x from the memory. >>clear x Erasing all the variable from the memory >>clear

MATLAB clones MATLAB is an excellent software but it is not free and not cheap. This is the reason why someone may consider trying out a free alternative of MATLAB. There are some free MATLAB clones or MATLAB-like applications such as: GNU Octave, SciLab and Rlab. The home page of Octave: https://www.gnu.org/software/octave/ The home page of Scilab: http://www.scilab.org/en/scilab/about The home page of Rlab: http://rlab.sourceforge.net Octave is the most compatible with MATLAB of all the clones.

Octave MATLAB is an excellent software but it is not free and not cheap. This is the reason why someone may consider trying out a free alternative of MATLAB. There are some free MATLAB clones or MATLAB-like software such as: GNU Octave, SciLab and Rlab. The home page of Octave: https://www.gnu.org/software/octave/ The home page of Scilab: http://www.scilab.org/en/scilab/about The home page of Rlab: http://rlab.sourceforge.net Octave is the most compatible with MATLAB of all the clones.

Graphical User Interface (GUI) of Octave Launching Octave double-click the Octave (GUI) shortcut on the desktop, or find the Octave item and click it in the start menu Panels of the Octave desktop (in the default layout) File Browser Command Window Workspace Command History

Graphical User Interface (GUI) of Octave File Browser Workspace Command Window Command History

Graphical User Interface (GUI) of Octave Setting the current directory (or folder) The selection of the current directory is important when we want to read data from files or save data into files or run our own scripts or call our own functions. The path of the current directory is displayed on the right side of the toolbar. We can take a step upwards in the directory system by clicking the green upwards arrow (One directory up). We can directly select any path by clicking the rightmost blue open folder icon. This action invokes a common dialog window "Browse directories". If the current directory has been changed, the content of the selected directory will be displayed in the "File Browser" window.

References https://www.tutorialspoint.com/matlab/ http://mayankagr.in/images/matlab_tutorial.pdf https://www.mathworks.com/support/learn-with-matlabtutorials.html