Escolar Documentos
Profissional Documentos
Cultura Documentos
TO
MATLAB
Interactive Computation
Matrices, Vectors and Array operations, Character Strings, Command Line Functions,
Built In Functions, Saving and Loading Data, Plotting Simple Graphs
Figure Window
Editor Window
Workspace
Command History
FIGURE WINDOW
EDITOR WINDOW
Command Function
pwd shows the current working directory
cd changes the current working directory
dir lists contents of the current directory
ls lists contents of the current directory, same as dir
path gets or sets MATLAB search path
editpath modifis MATLAB search path
copyfile copies a fie
Indian Institute of Technology Guwahati 11
Basics of MATLAB
Some useful commands to be remembered
Directory Information
Command Function
mkdir creates a directory
General Information
Command Function
computer tells you the computer type you are using
clock gives you wall clock time and date as a vector
date tells you the date as a string
more controls the paged output according to the screen size
ver gives the license and the MATLAB version information
bench benchmarks your computer on running MATLAB
compared to other computers
51
b) 5+1
1
>> theta=[0:5:90];
>> M =[ sind(theta); cosd(theta); tand(theta)];
>> M(:,theta==45)
ans =
0.7071
0.7071
1.0000
>> M(:,theta==0)
ans =
0
1
0
Indian Institute of Technology Guwahati 26
Basics of MATLAB (Tutorial + Simple Plots)
Simple Plots
Some simple commands related to plots. On-line help, type help plot in CW
Command Function
plot creates a 2-D line plot
axis changes the aspect ratio of the x-axis and the y-axis
xlabel annotates the x-axis
ylabel annotates the y-axis
title puts a title on the plot
TOOLSTRIP
TOOLSTRIP
Script file can also be executed by pressing the green arrowhead in the toolstrip or by
pressing F5
Error indicator strip at the extreme right end.
Indian Institute of Technology Guwahati 32
Basics of MATLAB (Script files)
TOOL STRIP
The colon
by itself as a
row or A row or a
column column of a
index matrix is deleted
specifies all by setting it to a
rows or null vector [ ] .
columns of
the matrix.
MATRIX
multiplication
is well defined
between
compatible
pairs. Their
dimensions
must agree
Square of a matrix
Concatenation of matrix
repmat command
is used to replicate
element-by- a matrix
element squaring
0 A(6:15,6:15)=zeros(10,10) A(1:5,16:20)=zeros(5,5)
0 0
2
2
2 4
4 8
4
10
12
6
6 14
16
8 18
8
20
0 5 10 15 20
10 nz = 275
10
12 A(16:20,16:20)=zeros(5,5)
12 0
2
14
14 4
16 8
16
10
12
18
18 14
16
20 18
20
20
0 5 10 15 20
0 5
Indian Institute
10
of Technology
15
Guwahati
20
0 5 10
nz = 250
15 20
46
nz = 400
nz = 300
Basics of MATLAB (Arrays Tutorial)
A=diag(1:6)+diag(7:11,1)+diag(12:15,2)+diag(16:18,3)+diag(19:20,4)+diag(21,5)
A= triu(A,1)'+A
>> A=rand(10);
>> A=A.*100;
>> A=fix(A);
>> A(A<10)=0;
>> A(A>90)=inf;
Indian Institute of Technology Guwahati 50
>> b = A(30<=A<=50);
Basics of MATLAB (Arrays Tutorial)
The publisher publishes a script in several formats , including HTML , XML , MS Word, PowerPoint , and Latex
First , open a new file in the editor and enter the following lines (including blank lines) . The only thing new here is the double
percent (%%) character. It indicates the beginning of a new cell
The text in a line beginning with %% is used as the title of that section (or cell) by the publisher
r= exp(-theta/10); %compute r
polar(theta,r)
publish('Report_Generation','html')
cd html;
open Report_Generation.html
Indian Institute of Technology Guwahati 58
Basics of MATLAB (Graphics and GUI)