The structural unit of data in any MATLAB program is the array. An array is a collection of record values organized into rows and columns and known by a single name. Individual data values within an array may be accessed by including the name of the array, followed by subscripts in parentheses that identify the row and column of the particular value. Even scalars are acted as arrays by MATLAB: they are arrays with only one row and one column. When MATLAB executes, it can display various types of windows that accept commands or display data.
There are three most important types of windows are:
Command Windows: where commands may be entered
Figure Windows: which display plots and graphs
Edit Windows: This permits a user to create and modify MATLAB programs.
When we start MATLAB Version 7.4, a specific window known as the MATLAB desktop appears. The desktop is a window that includes other windows display MATLAB data, plus toolbars and a "Start" button similar to that used by Windows XP. By default, most MATLAB tools are "docked" to the desktop so that they develop inside the desktop window. However, the user can choose to "undock" any or all tools, making them appear in windows separate from the desktop.
It integrates various tools for managing data, variables, and applications within the MATLAB environment.
The main tools within or accessible from the MATLAB desktop are
We will discuss the functions of these tools, one by one.
This is the main window. It is characterized by the MATLAB command prompt (>>). When you launch the function program, MATLAB puts you in this window. All commands containing those for running user-written programs are typed in this window at the MATLAB prompt. In MATLAB, this window is a part of the MATLAB that contains other smaller windows or panes.
Here is an image of the screen that appears when you open the MATLAB.
We will start working with the Command Window.
MATLAB Command Window Drop Downs-Show Command Window Actions
MATLAB Command Window Drop Downs-Browse for Functions
MATLAB Command Window-Command Line
MATLAB Command Window-Working at Command Line
Type here anything you want. Anything entered at the Command Line is treated as a command. For example, there are six types of commands entered to explain their meaning.
When we entered the above text, many things happened internally:
Let's take one more example:
Recalling Commands in MATLAB
Command History Window
All commands typed on the MATLAB prompt in the command window get documented, even across various sessions in this window. We can selected command from this window with the mouse and execute it in the command window by double-clicking on it. We can also select a set of commands from this window and create an M-file with the right click of the mouse (and selecting the suitable option from the menu).
The output of all graphics commands we copied in the command window is flushed to the graphics or figure window, a separate gray window with (default) white background color. The client can create as many figure windows as the system memory will allow.
This is where we write, edit, create and save our programs in files known as M-files. We can use any text editor to carry out these functions. MATLAB supports its built-in editor. However, we can use our editor by typing the standard file-editing commands that we usually use on our system. From within MATLAB, the command is typed at the MATLAB prompt, ensuring the exclamation character (!). The exclamation character prompts MATLAB to return the control temporarily to the local operating system, which executes the commands providing the character. After the editing is completed, the control is returned to the MATLAB.
Docking and Undocking Windows
MATLAB windows such as the Command Window, the Edit Window, and Figure Windows can either be docked to the desktop, or they can be undocked. When a window is docked, it occurs as a pane within the MATLAB desktop. When it is undocked, it occurs as an independent window on the computer screen separate from the desktop. When a window is docked to the desktop, the upper right-hand corner includes a small button with an arrow pointing up and to the right ↑ . If this button is clicked, the window will become an independent window. When the window is an independent window, the upper right-hand corner includes a small button with an arrow pointing down and to the right ↓. .If this button is clicked, the window will be re-docked with the desktop.
A statement such as
z = 10
creates a variable named z, stores the value 10 in it, and store it in a part of computer memory known as the workspace. A workspace is the set of all the variables and arrays that can be used by MATLAB when a specific command, M-file, or function is executing. All commands executed in the Command Window (as well as all script files executed from the Command Window) share a simple workspace, so they can all share variables. MATLAB operation differs from script files in that each operation has its separate workspace.
A list of the variables and arrays in the current workspace can be developed with the whos command. For example, after M-files calc_area and sin_x are executed, the whos command will display the following list of variables:
Script file calc_area created variables area, radius, and string, and script file sin_x created variables x and y.
Note: All the variables are in the same workspace, so if two script files are executed in succession, the second script file can use variables created by the first script file.
The contents of any variable or array may be determined by typing the appropriate name in the Command Window. For example, the contents of the string can be found as follows:
The area of the circle is 19.635
A variable can be removed from the workspace with the clear command.
The clear command takes the form
clear var1 var2 ...
where var1 and var2 are the names of the variables to be deleted. The command clear variables or simply clear remove all variables from the current workspace.
MATLAB gives online help for all its built-in functions and programming language constructs. The command lookfor, help, helpwin, and helpdesk implement on-line help.
MATLAB has a display program that shows many of its features. Type demo at the MATLAB prompt to invoke the demonstration program, and follow the information on the screen.
MATLAB provides interactive computation taking the input from the screen and flushing the output to the screen. It can read input data and write output data.
The following characteristics hold for all forms of input-output:
The component data type in MATLAB is an array. It encompasses various distinct data objects: integers, doubles (real numbers), matrices, character strings, structures, and cells.
Dimensioning is automatic in MATLAB. No dimension statements are needed for vectors or arrays. We can find the dimension of a current matrix or a vector with the size and length (for vectors only) commands.
MATLAB is case-sensitive for variable names and built-in functions. Thus a and A are different variables. Some MATLAB commands and built-in function calls are typed in lowercase letters. We can turn case sensitivity on and off with the casesen command.
The output of every command is presented on the screen unless MATLAB is directed otherwise. A semicolon at the end of a command contains the screen output, except for graphics and on-line help commands.
The following table presents the printed value of 10π in seven different formats.
The additional formats, format compact and format loose, control the spacing above and following the displayed lines, and format +displays a +, -,and blank for positive, negative, and zero numbers, respectively. The default is format short.
MATLAB can read and write different types of files for saving data or programs that we are likely to use often:
M-files are standard ASCII text data, with a .m extension to the filename.
There are two types of M files:
Most programs we write in MATLAB are saves as M-files. All built-in functions in MATLAB are M-files, most of which reside on our computer in a precompiled format. Some built-in functions are supported with source code in readable M-files so that they can be copied and modified.
MAT-files are binary information files with a .mat extension to the file name. Mat-files are created by MATLAB when you save a record with save command. The record is written with a special format that only MATLAB can read. Mat-files can be loaded into MATLAB with the load commands.
Fig-files are binary figure files with a .fig extension that can be open again in MATLAB as figures. Such files are created by saving a figure in the format using the Save or Save As options from the File menu or using the saveas command in the command window. A fig-file contains all the data required to recreate the figure. Specific files can be opened with the open filename.fig command.
P-files are compiled with a .p extension that can be executed in MATLAB directly (without being parsed and compiled). These files are created with the pcode command. If you develop an application that other person can use, but you do not want to provide them the source code (M-file), then you provide them the corresponding p-code or the p-file.
Mex-files are MATLAB-callable FORTRAN, C, and Java programs, with a .mex extension to the filename.