GMgKe586q6suSQnyqZLlGCooeWM

Pages

Search

Wednesday, December 22, 2010

Matrics In Matlab

To create a matric, type:
>> data = [1 2;
           3 4] 

>> data(1,2)    % Get the cross of the 1st row and the 2nd column
2               % var(row, col)

>> data(end,end)   % Get the end of row and column
4

>> data(1:2,1)  % Get elements cross at rows 1 till 2 and col 1
1
3

>> data(1:2,1:2)   % Get rows 1 till 2 and col 1 till 2
1 2                % var(r1:r2, c1:c2)
3 4                % r1:r2 = row1 till row2

>> data(:,1)    % Get all rows at col 1
1
3

>> data(1,:)    % Get all rows at row 1
1 2

>>  data(:)    % Get all elements in consecutive order

Detele rows or columns:
>> data(1,:)    % Delete all elements at the first row
>> data(:,1)    % Delete all elements at the first column

Generating built in matric style:
>> zeros(r,c)    % Creating zero matrix by r and c dimension
>> magic(d)      % Creating random matrix by d and d dimension
>> ones(r,c)     % Creating 1 matrix by r and c dimension
>> rand(r,c)     % Creating random matrix by r and c dimension
>> randn(r,c)    % Creating random matrix (negative included) 
                 % by r and c dimension
>> eye(d)        % Creating a diagonal matrix
          
Share/Bookmark

1 comment: