You are on page 1of 20

INTRODUCTION TO MATLAB

Bushra Fatima
NED University of Engineering & Technology
May 18, 2020
Outline
• Different windows in MATLAB

• Command Window

• Command History Window

Textbook: A. Gilat, Matlab: An Introduction with Applications 6th Edition. John Wiley
& Sons, Incorporated, 2016. (Chapter 1: Introduction)
INTRODUCTION TO MATLAB BUSHRA FATIMA
MATLAB WINDOW | COMMAND WINDOW | COMMAND HISTORY WINDOW 3 of 20

Different windows in MATLAB

METU NCC
INTRODUCTION TO MATLAB BUSHRA FATIMA
MATLAB WINDOW | COMMAND WINDOW | COMMAND HISTORY WINDOW 4 of 20

Default view of MATLAB desktop

CURRENT
FOLDER
WINDOW
COMMAND WINDOW

WORKSPACE
WINDOW

METU NCC
INTRODUCTION TO MATLAB BUSHRA FATIMA
MATLAB WINDOW | COMMAND WINDOW | COMMAND HISTORY WINDOW 5 of 20

Default view: Home  Layout  Default

METU NCC
INTRODUCTION TO MATLAB BUSHRA FATIMA
MATLAB WINDOW | COMMAND WINDOW | COMMAND HISTORY WINDOW 6 of 20

Command Window: Executing commands one at a time


• Main window: For executing commands
Command 1: A=5
press enter

To execute
Command line: The line with command prompt >>
Command 2: B=10 each
press enter
command:
Command 3: C=A+B
Press Enter
press enter

The cursor next to the command


prompt is prompting the user to enter
the next Command

METU NCC
INTRODUCTION TO MATLAB BUSHRA FATIMA
MATLAB WINDOW | COMMAND WINDOW | COMMAND HISTORY WINDOW 7 of 20

Command Window: Executing several commands

3 commands in the same


line separated by a
comma
Order of
execution:
Left to Right

METU NCC
INTRODUCTION TO MATLAB BUSHRA FATIMA
MATLAB WINDOW | COMMAND WINDOW | COMMAND HISTORY WINDOW 8 of 20

Command Window: Editing

• Editing:

The already executed command can not be corrected


and re-executed

METU NCC
INTRODUCTION TO MATLAB BUSHRA FATIMA
MATLAB WINDOW | COMMAND WINDOW | COMMAND HISTORY WINDOW 9 of 20

Command Window: Editing

Command-line editing:

• Left-arrow, Right-arrow

• Up-arrow and Down-arrow for accessing history

• Smart recall: type some character and press


Up-arrow and Down-arrow

METU NCC
INTRODUCTION TO MATLAB BUSHRA FATIMA
MATLAB WINDOW | COMMAND WINDOW | COMMAND HISTORY WINDOW 10 of 20

Command Window: Use of percent symbol (%)

Comment
Comment line is not executed when ENTER is
pressed

Comments are added to aid the programmer for his/her reference


METU NCC
INTRODUCTION TO MATLAB BUSHRA FATIMA
MATLAB WINDOW | COMMAND WINDOW | COMMAND HISTORY WINDOW 11 of 20

Command Window: Use of Semi-colon (;)

Output of the command is displayed

Output of the command


is not displayed
METU NCC
INTRODUCTION TO MATLAB BUSHRA FATIMA
MATLAB WINDOW | COMMAND WINDOW | COMMAND HISTORY WINDOW 12 of 20

Command Window: Use of Semi-colon (;)

METU NCC
INTRODUCTION TO MATLAB BUSHRA FATIMA
MATLAB WINDOW | COMMAND WINDOW | COMMAND HISTORY WINDOW 13 of 20

Command Window: Use of the command clc

clc  clears the command window only

CAUTION: The commands are CASE-SENSITIVE! METU NCC


INTRODUCTION TO MATLAB BUSHRA FATIMA
MATLAB WINDOW | COMMAND WINDOW | COMMAND HISTORY WINDOW 14 of 20

Drawbacks of a command window

• The commands in the Command window


cannot be saved and executed again.

• It is not interactive.

• Already executed command can not be


modified

• Better option: script file/editor


METU NCC
INTRODUCTION TO MATLAB BUSHRA FATIMA
MATLAB WINDOW | COMMAND WINDOW | COMMAND HISTORY WINDOW 15 of 20

Command Window: Font size: Home  Preferences  Fonts

METU NCC
INTRODUCTION TO MATLAB BUSHRA FATIMA
MATLAB WINDOW | COMMAND WINDOW | COMMAND HISTORY WINDOW 16 of 20

Useful commands you should know


CAUTION: The commands are CASE-SENSITIVE!

• help  lists all the primary help topics.

• help <command>  displays information about the command.

• doc On-line help  accesses the hypertext reference manual.

• doc <command>  displays information about the command.

• type <command>  Displays the actual MATLAB code for this


command.

• lookfor <keyword>  Searches all MATLAB commands for this


keyword.

METU NCC
INTRODUCTION TO MATLAB BUSHRA FATIMA
MATLAB WINDOW | COMMAND WINDOW | COMMAND HISTORY WINDOW 17 of 20

Useful commands you should know

ATTENTION: The commands are CASE-SENSITIVE!

• who  Lists all the current variables.

• whos  Lists all the current variables in more detail than who.

• save  Saves all of your variables.

• Ctrl + C  Abort the command which is currently executing (i.e., hold


down the control key and type c).

METU NCC
INTRODUCTION TO MATLAB BUSHRA FATIMA
MATLAB WINDOW | COMMAND WINDOW | COMMAND HISTORY WINDOW 18 of 20

Useful commands you should know

ATTENTION: The commands are CASE-SENSITIVE!

• clc  clears the command window (but does not clear the saved
variables in the workspace)

• clear all  deletes all the saved variables from the workspace (but
does not clear the command window) and brings the cursor at top

• clear variable  deletes only that particular variable from the


workspace

• date  gives current date

• calendar shows up the calendar of the ongoing month

METU NCC
INTRODUCTION TO MATLAB BUSHRA FATIMA
MATLAB WINDOW | COMMAND WINDOW | COMMAND HISTORY WINDOW 19 of 20

Busy…

METU NCC
INTRODUCTION TO MATLAB BUSHRA FATIMA
MATLAB WINDOW | COMMAND WINDOW | COMMAND HISTORY WINDOW 20 of 20

Command History

• The Command History Window  includes commands from previous


sessions.

• A command in the Command History Window can be used again in the


Command Window.

• By double-clicking on the command, the command is reentered in the


Command Window and executed.

• It is also possible to drag the command to the Command Window, make


changes if needed, and then execute it.

• Clearing Command history:


• Whole history
• A selection

METU NCC

You might also like