You are on page 1of 26

MATLAB

MATLAB V6.5

M AT L A B

A B mn. . .p x

.1


1.
A
>> A(:,:,1)=[1 2 3;2 3 1; 3 2 1]; >> A(:,:,2)=[2 4 6;4 6 2;6 4 2];
>> max(A) ans(:,:,1) = 3 3 3
ans(:,:,2) = 6 6 6 >> whos
Name Size Bytes Class

A 3x3x2 144 double array


ans 1x3x2 48 double array

Grand total is 24 elements using 192 bytes


. 1 A

>> TheSum=sum(A), TheCsum=cumsum(A)

TheSum(:,:,1) =

6 7 5 TheSum(:,:,2) = 12 14 10
TheCsum(:,:,1) =

1 2 3
3 5 4
6 7 5
TheCsum(:,:,2) =

2 4 6
6 10 8
12 14 10

>> x=[1 4 9 16 25];


>> d1=diff(x),d2=diff(d1),d3=diff(d2) d1 = 3 5 7 9
d2 = 2 2 2 d3 = 0 0

>> A=[1 1;2 2;3 3;4 100];


>> average=mean(A),med=median(A),dev=std(A)
average = 2.5000 26.5000
med = 2.5000 2.5000
dev = 1.2910 49.0068

(a)
>> x=[1 1 1];y=[1 2 2];z=[0 -1 1];
>> varx=cov(x), vary=cov(y), varz=cov(z)
varx = 0 vary = 0.3333 varz =1

(b)
>> Cvxy=cov(x,y),Cvxz=cov(x,z),Cvyz=cov(y,z)
Cvxy =
0 0
0 0.3333

Cvxz =
0 0
0 1
Cvyz =

0.3333 0
0 1.0000

(a) [Ascend,Ind]=sort

>> A=[0 4 4;2 0 2;4 2 0]; >> [Ascent,Ind]=sort(A)
Ascent =
0 0 0
2 2 2
4 4 4
Ind =
1 2 3 [B,Ind]=sort(A) I n d
B B A
2 3 2
I n d
3 1 1 i n d

hist bar stairs




x
>> x=[1 1 3 4 5 1 9 8];
>> hist(x);title('Histogram of x use hist')

(b)

>> hist(x,3); title('Histogram of x using hist(x,3)')



(c)
>> bar(x); title('bar(x)');



stem(x) x

diff

m

m
temps.m

temps

>> d=1:31; % number the days of month


>> plot (d, temps), xlable('Day of Month'),ylabel('Celsius'),title('Daily
High temperature in three cities')

>> avgtemp=mean(temps)
avgtemp = 11.9677 8.2258 19.8710
>> avgavg=mean(avgtemp) avgavg =13.3548

>> for i=1:3 tdev(:,i)=temps(:,i)-avgtemp(i); end

3*31)Matrix

diff

>> dailychange=diff(temps)

matlab

You might also like