Sie sind auf Seite 1von 5

>> load somefile.

dat
>> load someOtherFile.dat

>> save hello.txt v -ascii


_________________
suppose A =
1 2
3 4
5 5
>> A([1,3],:)
1 2
5 6
>> A = [A, [100; 101; 102]]
A =
1 2 100
3 4 101
5 6 103
>>A(:)
ans =
1
3
4
2
4
6
100
101
102
>>A = [1 2; 3 4];
>>B = [9 8; 7 6];
>>C = [A B]
ans
1 2 9 8
3 4 7 6
>>C = [A;B]
1 2
3 4
9 8
7 6
______________________________________
^^A, B, C ^^
>> A .^2
ans
1 4
9 16
>> exp(v)
>> abs(v)
>> -v

%save as text ascii

>> 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!

increment all elements of v..


>>v + ones(length(v),1)
basically adding an Identity matrix of dim length(v) * 1

>>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

//row wise.. max of ith element


//col wise..max of the jth element

>> 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)))))

//sum of elements of the minor diag of

___________________________________________________
===================================================
|-------------|
|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'

%saves into myplot.png, default dir..

>>figure(1); plot(t,y1);
>>figure(2); plot(t,y2);
OVERWRITEING the prev window

%plots the sin in some window


%plots the cos in SOME OTHER WINDOW, NOT

>>subplot(1,2,1)
ess the first area of the grid
>>plot(y,y1)
>>subplot(1,2,2)
>>plot(t,y2)

%divides the plot into 1*2 grid, and acc

>>axis([0.5 1 -1 1])
from -1 to 1

% x axis ranges from 0.5 to 1, y ranges

% using the 2nd area of the window

OKAY ..try this..this is fun..


>> imagesc(A)
>> imagesc(magic(15)), colorbar, colormap grey;

________________________________________________________________________________
___
================================================================================
===
---------------------------------------------------------------------------------______________________
||====================||
|| 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;

%% ----- IF, ELSE IF, ELSE ---- %%


>> if v(1) == 2,
>
disp('The Val is one');
> elseif v(1) == 2,
>
disp('the val is two');
> else
>
disp('the val is not one or two! ');

>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

Das könnte Ihnen auch gefallen