Wed Mar 09, 2011 10:07 pm
%% clear the screen of the Matlab console .
clc;
%% define matrix 1x1 with value =2
x=2
%% power of 2
powerX=power(x,2)
%% or same operation
powerX=x.^2
%% define two matrices 1 row x 4 columns
matrix1=[1 2 3 4];
matrix2=[1 1 1 4];
%% Add,subtract ,Divide two matrices. (must be same rows x cols )
addmatrix=matrix1+matrix2
submatrix=matrix1-matrix2
divmatrix=matrix1/matrix2
%% Define two matrices (note char(;) is used to create new row )
A = [1 2 3;43 3 4]; %% 2x3 matrix
B = [3 4 ; 2 3; 5 5]; %% 3x2 matrix
C =A*B %% 2x2 matrix
%% Inverse of matrix
inverseC=inv(C)
%% Define matrix using special function
onesMatrix=ones(3,3) % matrix of ones 3 rows x 3 columns.
zerosMatrix=zeros(3,5) % matrix of zeros 3 rows x 5 columns.
%% Mean of matrix
meanC=mean2(C)
%% Standard deviation
stdC=std2(C)
%% Partion of matrix
partMatrix=C(1,:) % take the first row , so it creates a partix 1x2 ( note char(:) means all elements)
%% if condition
%% remmber x =2 ;
if x==2
display('x equal 2');
%% end of if condition
end
%% Get the size of matrix (rows ,cols)
[rows,cols]= size(C) %% rows =2 , cols=2
%% for loop
for i=1:rows
for j=1:cols
%% print all the content of C matrix 22 ,25,155,201
C(i,j)
end
end
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com
Powered by phpBB © phpBB Group.