You are on page 1of 17

Matlab

Matrix
Lab

command

Command
1+1
2

x=1+1
x=2

z=y+x+3;
z=abs(x);

Data
x=[1 2 3;4 5 6]
123
456

z=[0.1:0.1:10];
size(x) = 2 3
x(1,2) = 2
x(:,2)
2
5

x(2,:)
456

x(2,1:2)
45

y=x
14
25
36


Matrix */

x=[1 2;3 4]
12
34

y=[1 1;2 2]
11
23

x+y
23
57

x*y
5 7
11 15

x/y
-1 1
11

x./y
1 2
1.5 1.33

m fileMatlab

or


Input

Process

Output


goto
if ()

Logic
& | ~ ==

% Remark
else
end

while ()
end

For count=1:2:N
end

Procedure & Function


.m
Procedure

function [a,b]=dog(c,d);
Ex: function [mean,stdev] = stat(x)
%STAT Interesting statistics.
n = length(x);
mean = avg(x,n);
stdev = sqrt(sum((x-avg(x,n)).^2)/n);

help

whos
clear
clf
end

plot(x);
plot(x,+r,y,xg);
plot([0.05:0.05:10],y(101:300));
axis([0 100 0 5]);
subplot(211);
clf;

RW
load vs save
save c:\1102\dat a -ascii
a=load(c:\1102\dat);

fscanf vs fprintf

fid=fopen(c:\temp\test.dat,r);
fscanf(fid,%g %g,a,b);
fclose(fid);
fid=fopen(c:\temp\test.dat,w);
fprintf(fid,\n%g %g,c,d);
fclose(fid);


for loop
1 2 3 4 5 . 50
6 7 8 9 10 ..55

26 27 28 29 30 . 75

element*6
*5*2

You might also like