octave

Octave

what semicolon does it is says go to next row

A = [1 2; 3 4; 5 6] -> generates a 3 * 2 matrix 1 2 is the first and second column
V = [1 2 3] -> row vector
V = [1;2;3] -> column vector
V = 1;0.1;2 -> row vector with v incrementing by 0.1 till 2
v = 1:6 -> row vector with 1 -> 6 elements [1 2 3 4 5 6]
ones(2,3) generates a 2 by 3 matrix with all ones
C = 2*ones(2,3) it multiplies all 1's with 2 and it generates a matrix with all 2's

w = zeroes(1,3)
I = eye(4) 4 by 4 identity matrix (all diagonals 1)

Size of matrix

size(A, 1) -> rows
size(A,2) -> columns

length(A) -> gives size of longest dimension

get first 10 elements of a vector

v = priceY(1:10) 

Now v is first 10 elements of Y

get a particular element or particular row (":" means every element along that row or column)

A(3,2) will get element 3rd row 2nd columns

A(2,:) gets everything in 2nd row ->

A(:,2) gets everything in 2nd column

A([1,3],:) -> get everything from 1st and 3rd row and all columns

A(:,[1,3]) -> get all rows but just 1st and 3rd columns

A(:,2) = [10,11,12] -> replace 2nd column by 10, 11 and 12

Append a column vector to right

A = [A, [100; 101; 102]]

Put all elements of A in single vector

A(:)

Concatenate 2 matrix

C = [A B]

Add one to all elements

v + ones(length(v),1) also we can do just v+1

control loop

for i=1:10,
    v(i) = 2^i
end;

if v(1) == 1,
    disp('value is one')
elseif v(1) == 2,
    disp('value is 2')
else 
    disp('value is not one or 2')
end;

results for ""

    No results matching ""