Beruflich Dokumente
Kultur Dokumente
dat
>> load someOtherFile.dat
>> v + ones(length(v),1)
>>lemgth (v)
ans
2
>>a = [1 15 2 4]
>>find(a<3)
ans
1 0 1 0
>>sum(a)
22
>>
>>
>>
>>
>>
>>
>>
>>
floor(a)
ceil(a)
rand(3)
A.*B
A./B
A*B
log(v)
abs(v)
//element wise..
//element wise..
// matrix wise op!
>>val = max(a)
or
>>[val, ind]
= max(a)
>>a = [1, 15, 2, 0.5];
>>a<3
ans =
1 0 1 1
>> find (a<3)
1 3 4
>> sum(a)
ans =
18.500
>> prod(a)
ans =
15
>>max(rand(2), rand(2)) // max of the element at ij pos of A and B...try it out.
.
>> M = magic(3)
ans =
8 1 6
3 5 7
4 9 2
>>max(A,[],1)
ans =
8 9 7
>>max(A,[],2)
ans=
8
7
9
>>max(A)
ans =
8 9 7
>> max(A(:))
ans=
9
>>
>>
>>
A
>>
A
sum(A,1)
//sum of row elements of A
sum(A,2)
//sum of col elements of A
sum(sum(A.*eye(9)))
//sum of elements of the major diag of
sum(sum(A.*flipud(eye(length(A)))))
___________________________________________________
===================================================
|-------------|
|PLOTTING DATA|
|=============|
>>
>>
>>
>>
>>
>>
t = [0:0.01:0.98];
y1 = sin(2*pi*4*t);
plot(t,y1);
hold on;
y2 = cos(2*pi*4*t);
plot(t,y1,'r');
>>xlabel('time')
>>ylabel('value')
>>legend('sin', 'cos')
>>title('myPlot)
>>print -dpng 'myPlot.png'
>>figure(1); plot(t,y1);
>>figure(2); plot(t,y2);
OVERWRITEING the prev window
>>subplot(1,2,1)
ess the first area of the grid
>>plot(y,y1)
>>subplot(1,2,2)
>>plot(t,y2)
>>axis([0.5 1 -1 1])
from -1 to 1
________________________________________________________________________________
___
================================================================================
===
---------------------------------------------------------------------------------______________________
||====================||
|| CONTROL STATEMENTS ||
||____________________||
>> v = zeros(10,1);
%%------ FOR LOOP ------%%
>> for i=1:10,
>
v(i)=2^i;
> end;
%% ---- WHILE LOOP---- %%
>>i =1
>> while i<=5,
>
v(i)= 100;
>
i = i+ 1;
> end;
>>i = 1;
>> while
>
>
>
>
>
> end
true,
v(i)=999;
i = i+1;
if i == 6,
break;
end;
>end;
____________________________
|============================|
| FUNCTIONS
|
|____________________________|
__________________________________
function y = squareThisnumber(x)
y = x^2;
==================================
>>
%octave search path..
>> addpath('C:\users\');
___________________________________
function[y1,y2] = squareAndCube(x)
y1 = x^2;
y2 = x^3;
===================================
>>[a,b] = squareAndCube(5);
>>a
ans = 25
>>b
ans = 125