0% found this document useful (0 votes)
24 views4 pages

Introduction to MATLAB Basics

This document introduces MATLAB by describing its starting, quitting, and basic desktop tools. It explains how to start and quit MATLAB, and describes the main desktop components - the Command Window, Command History, Current Directory Browser, Workspace, and Editor/Debugger Window. It also outlines some basic MATLAB commands like clear, clc, help, edit, and more. It provides examples of using semicolons, line continuation, and comments. It includes exercises to edit functions, get help, and use clear on a single variable.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views4 pages

Introduction to MATLAB Basics

This document introduces MATLAB by describing its starting, quitting, and basic desktop tools. It explains how to start and quit MATLAB, and describes the main desktop components - the Command Window, Command History, Current Directory Browser, Workspace, and Editor/Debugger Window. It also outlines some basic MATLAB commands like clear, clc, help, edit, and more. It provides examples of using semicolons, line continuation, and comments. It includes exercises to edit functions, get help, and use clear on a single variable.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Experiment No.

(1) Introduction to MATLAB

Experiment No. ( 1 )
Introduction to MATLAB

1-1 Introduction

MATLAB is a high-performance language for technical computing. It integrates


computation, visualization, and programming in an easy-to-use environment where problems
and solutions are expressed in familiar mathematical notation.
The name MATLAB stands for matrix laboratory. MATLAB was originally written to
provide easy access to matrix.

1-1-1 Starting and Quitting MATLAB

• To start MATLAB, double-click the MATLAB shortcut icon on your Windows


desktop. You will know MALTAB is running when you see the special
" >> " prompt in the MATLAB Command Window.

• To end your MATLAB session, select Exit MATLAB from the File menu in the
desktop, or type quit (or exit) in the Command Window, or with easy way by
click on close button in control box.

1-1-2 Desktop Tools

1- Command Window: Use the Command Window to enter variables and run
functions and M-files.
2- 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.
3- Current Directory Browser: MATLAB file operations use the current directory
reference point. Any file you want to run must be in the current directory or on the
search path.
4- Workspace: The MATLAB workspace consists of the set of variables (named
arrays) built up during a MATLAB session and stored in memory.
1
Experiment No. (1) Introduction to MATLAB

Current Directory Browser Command Window

Workspace

Command
History

5- Editor/Debugger Window: Use the Editor/Debugger to create and debug M-files.

2
Experiment No. (1) Introduction to MATLAB
1-2 Basic Commands

• clear Command: Removes all variables from workspace.


• clc Command: Clears the Command window and homes the cursor.
• help Command: help <Topic> displays help about that Topic if it
[Link] help topics and returning those that contains a key word you.
• edit Command: enable you to edit (open) any M-file in Editor Window. This
command doesn’t open built-in function like, sqrt. See also type Command.
more command: more on enables paging of the output in the MATLAB
command window, and more off disables paging of the output in the MATLAB
command window.

Notes:

• A semicolon " ; " at the end of a MATLAB statement suppresses printing of results.
• If a statement does not fit on one line, use " . . . ", followed by Enter to indicate that
the statement continues on the next line. For example:

>> S= sqrt (225)*30 /...


(20*sqrt (100)
• If we don’t specify an output variable, MATLAB uses the variable ans (short for
answer), to store the last results of a calculation.
• Use Up arrow and Down arrow to edit previous commands you entered in
Command Window.
• Insert " % " before the statement that you want to use it as comment; the statement
will appear in green color.

3
Experiment No. (1) Introduction to MATLAB

Now Try to do the following:

>> a=3

>> a=3; can you see the effect of semicolon " ; "

>> a+5 assign the sum of a and 5 to ans

>> b=a+5 assign the sum of a and 5 to b

>> clear a

>> a can you see the effect of clear command

>> clc clean the screen

>> b

Exercises

1- Use edit command to edit the dct function, then try to edit sin function. State the
difference.

2- Use help command to get help about rand function.

3- Enter a=3; b=5; c=7, then clear the variable b only

Common questions

Powered by AI

Using semicolons in MATLAB scripts suppresses output display, enhancing performance by reducing unnecessary computation load in the Command Window, especially when running scripts with numerous calculations. Comments, marked by '%', facilitate collaboration by providing explanatory notes in the code, leading to better understanding and maintainability for teams. These practices promote efficient use of computational resources and improve the readability and shareability of code among developers .

Using the 'clear' command without any arguments in MATLAB removes all variables from the Workspace, effectively resetting the environment's memory state concerning stored variables. Using 'clear' with specified variable names, however, removes only the indicated variables, allowing selective memory management. This allows users to manage memory efficiently, keeping only relevant data and preventing unnecessary loss of all stored computations and settings .

MATLAB handles command formatting by allowing statements to span multiple lines with the use of '...'. Output suppression is achieved by appending a semicolon ';' at the end of a statement, preventing the display of results in the Command Window. This feature is useful for managing large amounts of output and maintaining clean command line visibility. The implication for programming is that developers can control computational feedback and focus on critical outputs without overwhelming unnecessary data display .

In MATLAB, memory management involves the Workspace, where all session variables are stored as named arrays. The 'clear' command removes all variables from the Workspace, thereby freeing up memory. Additionally, the 'ans' variable temporarily stores the last result if no explicit output variable is specified. Variables can only persist within a session unless explicitly saved to files. The 'clc' command clears the Command Window without affecting the stored variables .

To modify and run an M-file in MATLAB, start by opening the MATLAB interface and accessing the Editor/Debugger Window by entering 'edit' followed by the name of the M-file. This allows editing of the script or function. After making the necessary changes, save the file. Navigate back to the Command Window, ensure the current directory is set to where the file is located, and execute the file by typing its name without the '.m' extension .

MATLAB offers several user-friendly features that enhance the programming experience, such as intuitive mathematical notation expression, easy integration of computation and visualization, and a cohesive programming environment. The Command History simplifies re-execution and modification of previous commands, and the ability to edit commands using arrow keys increases efficiency. Comments in code are marked with '%', appearing in green for easy identification. The interface allows easy navigation and management of scripts and functions through the Editor/Debugger .

The main components of the MATLAB interface are the Command Window, Command History, Current Directory Browser, Workspace, and Editor/Debugger Window. The Command Window is used to enter variables and run functions and M-files. Command History logs the statements entered in the Command Window, allowing users to view, copy, and execute previous commands. The Current Directory Browser handles file operations from a reference point necessary for running files. The Workspace stores a set of variables built up during a MATLAB session. The Editor/Debugger Window is used for creating and debugging M-files .

The 'edit' command in MATLAB opens the specified M-file in the Editor Window for editing. It allows modification of scripts and user-defined functions but does not open built-in functions such as 'sqrt'. The 'type' command, in contrast, displays the content of the specified M-file or function directly in the Command Window without allowing edits. This makes 'edit' more suitable for development and debugging, while 'type' is primarily used for quick reference .

MATLAB implements command history functionalities through the Command History feature, which logs and displays all previously entered commands. Users can view, copy, and quickly re-execute commands from this log, streamlining coding tasks and reducing repetitive data entry. This feature enhances programming by facilitating bug tracking, allowing iterative testing of changes, and promoting efficient workflow by reapplying command sequences with minimal effort .

The Current Directory Browser in MATLAB is crucial for file management as it sets the reference point for MATLAB file operations. Any file that users intend to execute must either be located in the current directory or be specified in the search path. This allows easy organization and access to necessary files and ensures that functions and scripts can run successfully without path-related errors .

You might also like