Labs System Modeling

MATLAB DEVELOPMENT ENVIRONMENT

Objectives

Learn about Matlab Development Environment
Learn about the starting and quitting Matlab
Learn about Matlab desktop
Learn about Matlab desktop tools

Prerequisites

Students are expected to be familiar with Windows system
Students should have basic knowledge of any text editors

Requirement

Matlab software any version

Remarks

This lab session will be evaluated and it will carry 2 % of your activity credit points.
All the source codes and executables related to this lab session should be saved in a folder
named Lab1. If not, zero marks will be given. Before you leave the lab make sure you show to your instructor that you have saved your file in Lab1 folder.

Starting and Quitting MATLAB

Starting MATLAB

On Windows platforms, to start MATLAB, double-click the MATLAB shortcut icon on your Windows desktop.

You can change the directory in which MATLAB starts, define startup options including running a
script upon startup, and reduce startup time in some situations.

Quitting MATLAB

To end your MATLAB session, select Exit MATLAB from the File menu in the desktop, or type
quit” in the Command Window. To execute specified functions each time MATLAB quits, such as saving the workspace, you can create and run a name.m” script.

MATLAB Desktop

When you start MATLAB, the MATLAB desktop appears, containing tools (graphical user interfaces) for managing files, variables, and applications associated with MATLAB.

You can change the way your desktop looks by opening, closing, moving, and resizing the tools in it.
Use the View menu to open or close the tools. You can also move tools outside the desktop or move
them back into the desktop (docking). All the desktop tools provide common features such as context
menus and keyboard shortcuts.

You can specify certain characteristics for the desktop tools by selecting Preferences from the File
menu. For example, you can specify the font characteristics for Command Window text. For more
information, click the Help button in the Preferences dialog box.

Desktop Tools

This section provides an introduction to the MATLAB desktop tools. You can also use MATLAB
functions to perform most of the features found in the desktop tools. The tools are

  • Command Window
  • Command History
  • Start Button and Launch Pad
  • Help Browser
  • Current Directory Browser
  • Workspace Browser
  • Array Editor
  • Editor/Debugger

Command Window

Use the Command Window to enter variables and run functions and M-files. In
this example, MAGIC(4) is called to create an 4-by-4 matrix with the integers from 1 through 4 = 16
with equal row, column, and diagonal sums.

A=magic(4);

Command History

Statements you enter in the Command Window are logged in the Command History. In the Command
History, you can view previously run statements, and copy and execute selected statements. In green is given the date/time when the execution of the commands took place.

To save the input and output from a MATLAB session to a file, use the diary function as the follows:

diary filename

After finishing writing into the file, use

diary off

to close the file.

Start Button

The MATLAB Start button provides easy access to tools, demos, and documentation. Just click the
button to see the options as shown in Figure below.

fig1.png

Help Browser

Use the Help browser to search and view documentation and demos for all your MathWorks products.
The Help browser is a Web browser integrated into the MATLAB desktop that displays HTML
documents.

To open the Help browser, click the help button in the toolbar,

fig2.png

Press F1, or type helpbrowser in
the Command Window and the following image will appear (see Figure below).

fig3.png

The Help browser consists of two panes, the Help Navigator, which you use to find information, and
the display pane, where you view the information. Tabs in the Help Navigator pane provide different
ways to find documentation and demos. Drag the separator bar to adjust the width of the panes. View
documentation in the display pane. Use the close box to hide the pane.

Help Navigator

Use the Help Navigator to find information. It includes

  • Product filter—set the filter to show documentation only for the products you specify.
  • Contents tab—view the titles and tables of contents of documentation for your products.
  • Index tab—find specific index entries (selected keywords) in the MathWorks documentation for your products.
  • Demos tab—view and run demonstrations for your MathWorks products.
  • Search tab—look for a specific word or phrase in the documentation. To get help for a specific function, set the Search type to Function Name.
  • Favorites tab—view a list of links to documents you previously designated as favourites.

Display Pane

After finding documentation using the Help Navigator, view it in the display pane. While viewing the documentation, you can

  • Browse to other pages—Use the arrows at the tops and bottoms of the pages to move through the document, or use the back and forward buttons in the toolbar to go to previously viewed pages.
  • Bookmark pages—Click the Add to Favorites button in the toolbar.
  • Print pages—Click the print button in the toolbar.
  • Find a term in the page—Type a term in the Find in page field in the toolbar and click Go.

Other features available in the display pane are copying information, evaluating a selection, and viewing Web pages.

For More Help

In addition to the Help browser, you can use help functions. To get help for a specific function, use doc. For example, doc format displays documentation for the format function in the Help browser.

fig4.png

If you type help followed by the function name, for instance ``help diary”, a briefer form of the documentation appears in the Command Window (see Figure below).

Other means for getting help include contacting Technical Support (http://www.mathworks.com/support) and participating in the newsgroup for MATLAB users, comp.soft-sys.matlab.

Current Directory Browser

MATLAB file operations use the current directory and the search path as reference points. Any file you want to run must either be in the current directory or on the search path.

A quick way to view or change the current directory is by using the Current Directory field in the desktop toolbar as shown in figure.

fig5.png

To search for, view, open, and make changes to MATLAB-related directories and files, use the MATLAB Current Directory browser. Alternatively, you can use the functions

dir
cd

and

delete

Search Path

MATLAB uses a search path to find M-files and other MATLAB-related files, which are organized in directories on your file system. Any file you want to run in MATLAB must reside in the current directory or in a directory that is on the search path. Add the directories containing files you create to the MATLAB search path. By default, the files supplied with MATLAB and MathWorks toolboxes are included in the search path.
To see which directories are on the search path or to change the search path, select Search Path from the File menu in the desktop and use the Set Path dialog box (shown in the figure below). Alternatively, you can use the path function to view the search path, addpath to add directories to the path, and rmpath to remove the directories from the path. You can have look at the help how to use "path" function in the MATLAB by typing "help path" in the Common Window( see figure below).

fig6.pngfig7.png

Workspace Browser

The MATLAB workspace consists of the set of variables (named arrays) built up during a MATLAB session and stored in memory (see figure below). You add variables to the workspace by using functions, running M-files, and loading saved workspaces.
to view workspace and information about each variable, use the Workspace Browser, or use the function "who" and "whos" , for example, typing

who a*

in the Command Window will show variable names starting with "a".
fig8.png
To delete variables from the workspace, select the variable and select Delete from theEdit menu. Alternatively, use the clear function.
The workspace is not maintained after you end the MATLAB session. To save the workspace to a file that can be read during a later MATLAB session, select Select Workspace As from the File menu. use the save function. This saves the workspace to a binary file called a MAT-file, which has a .mat extension.
There are options for saving to different formats. To read in a MAT-file, select Import Data from the File menu, or use load function.

Array Editor

Double-click a variable in the Workspace browser to see it in the Array Editor (as shown in Figure below). Use the Array Editor to view and edit a visual representation of one- or two-dimensional numeric arrays, strings, and cell arrays of strings that are in the workspace.
fig9.png

Editor/Debugger

Use the Editor/Debugger to create and debug M-files, which are programs you write to run MATLAB functions. The Editor/Debugger provides a graphical user interface for basic text editing, as well as for M-file debugging (see Figure below).

fig10.png

You can use any text editor to create M-files, such as TextPad, and can use preferences (accessible from the desktop File menu) to specify that editor as the default. If you use another editor, you can still use the MATLAB Editor/Debugger for debugging. If you just need to view the contents of an M-file, you can display it in the Command Window by using the type function.

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License