1.1: What is MATLAB?
- Page ID
- 9459
\( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)
\( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)
\( \newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\)
( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\)
\( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\)
\( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\)
\( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\)
\( \newcommand{\Span}{\mathrm{span}}\)
\( \newcommand{\id}{\mathrm{id}}\)
\( \newcommand{\Span}{\mathrm{span}}\)
\( \newcommand{\kernel}{\mathrm{null}\,}\)
\( \newcommand{\range}{\mathrm{range}\,}\)
\( \newcommand{\RealPart}{\mathrm{Re}}\)
\( \newcommand{\ImaginaryPart}{\mathrm{Im}}\)
\( \newcommand{\Argument}{\mathrm{Arg}}\)
\( \newcommand{\norm}[1]{\| #1 \|}\)
\( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\)
\( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\AA}{\unicode[.8,0]{x212B}}\)
\( \newcommand{\vectorA}[1]{\vec{#1}} % arrow\)
\( \newcommand{\vectorAt}[1]{\vec{\text{#1}}} % arrow\)
\( \newcommand{\vectorB}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)
\( \newcommand{\vectorC}[1]{\textbf{#1}} \)
\( \newcommand{\vectorD}[1]{\overrightarrow{#1}} \)
\( \newcommand{\vectorDt}[1]{\overrightarrow{\text{#1}}} \)
\( \newcommand{\vectE}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash{\mathbf {#1}}}} \)
\( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)
\( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)
\(\newcommand{\avec}{\mathbf a}\) \(\newcommand{\bvec}{\mathbf b}\) \(\newcommand{\cvec}{\mathbf c}\) \(\newcommand{\dvec}{\mathbf d}\) \(\newcommand{\dtil}{\widetilde{\mathbf d}}\) \(\newcommand{\evec}{\mathbf e}\) \(\newcommand{\fvec}{\mathbf f}\) \(\newcommand{\nvec}{\mathbf n}\) \(\newcommand{\pvec}{\mathbf p}\) \(\newcommand{\qvec}{\mathbf q}\) \(\newcommand{\svec}{\mathbf s}\) \(\newcommand{\tvec}{\mathbf t}\) \(\newcommand{\uvec}{\mathbf u}\) \(\newcommand{\vvec}{\mathbf v}\) \(\newcommand{\wvec}{\mathbf w}\) \(\newcommand{\xvec}{\mathbf x}\) \(\newcommand{\yvec}{\mathbf y}\) \(\newcommand{\zvec}{\mathbf z}\) \(\newcommand{\rvec}{\mathbf r}\) \(\newcommand{\mvec}{\mathbf m}\) \(\newcommand{\zerovec}{\mathbf 0}\) \(\newcommand{\onevec}{\mathbf 1}\) \(\newcommand{\real}{\mathbb R}\) \(\newcommand{\twovec}[2]{\left[\begin{array}{r}#1 \\ #2 \end{array}\right]}\) \(\newcommand{\ctwovec}[2]{\left[\begin{array}{c}#1 \\ #2 \end{array}\right]}\) \(\newcommand{\threevec}[3]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \end{array}\right]}\) \(\newcommand{\cthreevec}[3]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \end{array}\right]}\) \(\newcommand{\fourvec}[4]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \\ #4 \end{array}\right]}\) \(\newcommand{\cfourvec}[4]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \\ #4 \end{array}\right]}\) \(\newcommand{\fivevec}[5]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \\ #4 \\ #5 \\ \end{array}\right]}\) \(\newcommand{\cfivevec}[5]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \\ #4 \\ #5 \\ \end{array}\right]}\) \(\newcommand{\mattwo}[4]{\left[\begin{array}{rr}#1 \amp #2 \\ #3 \amp #4 \\ \end{array}\right]}\) \(\newcommand{\laspan}[1]{\text{Span}\{#1\}}\) \(\newcommand{\bcal}{\cal B}\) \(\newcommand{\ccal}{\cal C}\) \(\newcommand{\scal}{\cal S}\) \(\newcommand{\wcal}{\cal W}\) \(\newcommand{\ecal}{\cal E}\) \(\newcommand{\coords}[2]{\left\{#1\right\}_{#2}}\) \(\newcommand{\gray}[1]{\color{gray}{#1}}\) \(\newcommand{\lgray}[1]{\color{lightgray}{#1}}\) \(\newcommand{\rank}{\operatorname{rank}}\) \(\newcommand{\row}{\text{Row}}\) \(\newcommand{\col}{\text{Col}}\) \(\renewcommand{\row}{\text{Row}}\) \(\newcommand{\nul}{\text{Nul}}\) \(\newcommand{\var}{\text{Var}}\) \(\newcommand{\corr}{\text{corr}}\) \(\newcommand{\len}[1]{\left|#1\right|}\) \(\newcommand{\bbar}{\overline{\bvec}}\) \(\newcommand{\bhat}{\widehat{\bvec}}\) \(\newcommand{\bperp}{\bvec^\perp}\) \(\newcommand{\xhat}{\widehat{\xvec}}\) \(\newcommand{\vhat}{\widehat{\vvec}}\) \(\newcommand{\uhat}{\widehat{\uvec}}\) \(\newcommand{\what}{\widehat{\wvec}}\) \(\newcommand{\Sighat}{\widehat{\Sigma}}\) \(\newcommand{\lt}{<}\) \(\newcommand{\gt}{>}\) \(\newcommand{\amp}{&}\) \(\definecolor{fillinmathshade}{gray}{0.9}\)MATLAB stands for MATrix LABoratory (see Wikipedia) and is a commercial software application written by The MathWorks, Inc. When you first use MATLAB, you can think of it as a glorified calculator allowing you to perform engineering calculations and plot data. However, MATLAB is more than an advanced scientific calculator, for example MATLAB's sophisticated numerical computation environment also allows us to analyze data, simulate engineering systems, document and share our code with others.
Why Use MATLAB?
MATLAB has become a defacto standard in many fields of engineering and science. Even a casual exploration of MATLAB should unveil its computational power however a closer look at MATLAB's graphics and data analysis tools as well as interaction with other applications and programing languages prove why MATLAB is a very strong application for technical computing.
The standard MATLAB installation includes graphics features to visualize engineering and scientific data in 2-D and 3-D plots. We can interactivity build graphs and generate MATLAB command output that can be saved for use in the future. The saved-instructions can be called again with different data set to build new plots. The plots created with MATLAB can be exported in various file formats (e.g. .jpg, .png) to embed in Microsoft Word documents or PowerPoint slideshows.
MATLAB also contains interactive tools to explore and analyze data. For example, we can visualize data with one of the many plotting routines, zoom in to plots to take measurements, perform statistical calculations, fit curves to data and evaluate the obtained expression for a desired value.
MATLAB interacts with other applications (e.g. Microsoft Excel) and can be called from C code, C++ or Fortran programming language.
Running MATLAB
To use MATLAB, it must be installed on your computer and you can start it just like you start any application on your system or you must have access to a network where it is available.
BCIT holds a Total Student Headcount (TSH) license for Mathworks software and this allows students to install MathWorks software on their personally-owned computers.
Matlab download and installation instructions for BCIT students
For your install, choose the latest version available and install MATLAB, Curve Fitting Toolbox and Symbolic Math Toolbox.
In addition, MATLAB Online provides access to MATLAB from your web browser. Just log in to use MATLAB:
The MATLAB Desktop
When you start the MATLAB program, it displays the MATLAB desktop. The desktop is a set of tools (graphical user interfaces or GUIs) for managing files, variables, and applications associated with MATLAB. The first time you start MATLAB, the desktop appears with the default layout, as shown in the following illustration.
Figure \(\PageIndex{1}\). The MATLAB Desktop.
Command Window
The Command Window is where we execute MATLAB commands. We enter statements at the Command Window prompt. The prompt can be any one of the following:
Trial>>
indicates that the Command Window is in normal mode and the MATLAB license will expire after the trial period ends.EDU>>
indicates that the Command Window is in normal mode, in MATLAB Student Version.>>
indicates that the Command Window is in normal mode.
Figure \(\PageIndex{2}\). The Command Window.
Command History
The Command History is a log of the commands we have executed in the command window.
Figure \(\PageIndex{3}\). The Command History.
Workspace
The workspace consists of a set of variables stored in memory during a MATLAB session. To open the Workspace browser, select Desktop > Workspace in the MATLAB desktop, or type
>> workspace
at the Command Window prompt.
Figure \(\PageIndex{4}\). Workspace.
Current Folder
The Current Folder is like the Finder in Mac OS X or Windows Explorer in Windows operating systems and allows us to browse through the files and folders. The Current Folder also displays details about files in your current directory and within the hierarchy of the folders it contains.
Figure \(\PageIndex{5}\). Current Folder.
Figure \(\PageIndex{6}\). Current Folder docked on the desktop.
Tool Strip
The tool strip contains global tabs, Home, Plots and Apps. Contextual tabs become available when you need them.
Figure \(\PageIndex{7}\). Tool Strip.
Figure \(\PageIndex{8}\). Tabs.
The plots tab allows us to plot various types of graphs quickly and easily.
Figure \(\PageIndex{9}\). The plots tab.
The apps tab gives quick access to interactive applications within MATLAB environment.
Figure \(\PageIndex{10}\). The apps tab.
Layout button allows us to change the desktop layout or go back to the default configuration.
Figure \(\PageIndex{11}\). Layout button.
Toolbar
The MATLAB toolbar provides on-screen buttons to access frequently used features such as, copy, paste, undo and redo.
Figure \(\PageIndex{12}\). Toolbar.
Keyboard shortcuts
MATLAB provides keyboard shortcuts for viewing a history of commands and listing contextual help.
- The up arrow key,
- The tab key,
- The semicolon symbol.
The Up Arrow Key
Suppose we want to enter the following equation:
>> y=sin(45)
But we mistakenly entered
>> y=sine(45)
MATLAB returns the following prompt:
Callstack:
at (Bookshelves/Computer_Science/Applied_Programming/A_Brief_Introduction_to_Engineering_Computation_with_MATLAB_(Beyenir)/01:_Chapters/1.01:_What_is_MATLAB), /content/body/div[3]/div[3]/div/div[4]/div/div[1]/pre, line 2, column 35
Instead of retyping the equation, press the up arrow key, the mistakenly entered line is displayed. Using the left arrow key, move the cursor to the misspelled letter. Make the correction and press Return or Enter to execute the command.
Pressing the up arrow key repeatedly recalls the previously entered commands. Likewise, typing the first characters of previously entered line and pressing the up arrow key displays the full command line. To execute that line, simply press the Return or Enter key.
The Tab Key
Suppose you forgot how to enter the square root command. Begin typing y=sq
in the command prompt:
>> y=sq
Then press the tab key and scroll down to sqrt
. Select it and press Return or Enter key.
>> y=sqrt
The Semicolon Symbol
The semicolon symbol at the end of a line suppresses the screen output. This is useful when you want to keep your command window clean.
Type the following entry and press the Return key:
>> y=2+2
The following output is displayed:
y = 4
Now, press the up arrow key to recall our initial entry
>> y=2+2
And insert a semicolon as follows:
>> y=2+2;
No numerical result is displayed however MATLAB stores the value of y in the memory. We can recall the value y by simply typing y and pressing Return.
MATLAB Help
MATLAB comes with three forms of online help: help, doc and demos.
Help
Typing help in the Command Window lists all primary help topics. You can display a topic by clicking on the link.
>> help
Figure \(\PageIndex{13}\). Help.
Or if you know the command or function you need help with, you can type help followed by the command or function. For example to learn about clc
command, type help clc
at the command prompt:
>> help clc
Figure \(\PageIndex{14}\). The output of >> help clc
command.
Also try the following command: >> help clear
Figure \(\PageIndex{15}\). The output of
>> help clear
command.
To learn about sine function, type help sin
at the command prompt:
>> help sin
Doc
Obviously, to use help
effectively, you need to know what you are looking for. Often times, especially when you first start learning an application, it is usually difficult to ask the right questions. In the case of MATLAB, doc
command is generally better than help
. If you type doc
in the command prompt, MATLAB opens a browser from where you can obtain help easier:
>> doc
Figure \(\PageIndex{16}\).
Built-in MATLAB Documentation.
Like using help sin
, try typing doc sin
in the command prompt:
>> doc sin
Demos
You can learn more about MATLAB through demos by typing demo
in the command prompt, a list of links to demos will open in Help Browser. Demos and online seminars are available at product demos and online seminars.
>> demo
Figure \(\PageIndex{17}\).
Built-in MATLAB Demos.
Useful Commands and Functions
For a detailed explanation and examples for each of the following type ‘help function’ (without quotes) at the MATLAB prompt.
Useful commands and functions
Summary of Key Points
- MATLAB is a popular technical computing application and MathWorks offers a trial version of MATLAB on their website,
- The MATLAB Desktop consists of Command Window, Command History, Workspace, Current Folder and Start Button,
- The up/down arrow keys, the tab key and the semicolon are convenient tools to use the Command Window,
- MATLAB features an online help, doc and demo,
- Various commands and functions make MATLAB experience easier, for example,
clc, clear and exit
.