28
loading...
This website collects cookies to deliver better user experience
>> x=[1,2,3,4,5];
>> y=2*x
y =
2 4 6 8 10
>> z=x+y
z =
3 6 9 12 15
>> z=x-y
z =
-1 -2 -3 -4 -5
>> z=y.*x
z =
2 8 18 32 50
>> z=x./y
z =
0.5000 0.5000 0.5000 0.5000 0.5000
>> z=x.^y
z =
1 16 729 65536 9765625
When dealing with two matrices, always add a dot before operators for making element wise operators .*
, ./
and .^
. This is because normal operators are reserved for matrix operations.
>> x=[1,2,3;4,5,6]
x =
1 2 3
4 5 6
>> y=[1,2;3,4;5,6]
y =
1 2
3 4
5 6
>> x*y
ans =
22 28
49 64
>> x=[1,2,3,4,5,4,3,2,1,1];
>> mean(x)
ans =
2.6000
>> mode(x)
ans =
1
>> var(x)
ans =
2.0444
>> std(x)
ans =
1.4298
>> median(x)
ans =
2.5000
>> y=median(x).*x
y =
2.5000 5.0000 7.5000 10.0000 12.5000 10.0000 7.5000 5.0000 2.5000 2.5000
>> rms(x)
ans =
2.9326