Total members 10262 | Gratitudes |It is currently Wed May 23, 2012 9:57 pm Login / Join Codemiles


All times are UTC [ DST ]




Post new topic Reply to topic  Quick reply  [ 1 post ] 
Author Code Snippet
 Code subject: Matlab basics examples
PostPosted: Wed Mar 09, 2011 10:07 pm 
Offline
Mastermind
User avatar

Joined: Tue Mar 27, 2007 10:55 pm
Posts: 2279
Location: Earth
Has thanked: 39 time
Have thanks: 61 time

MATLAB basics examples : about arithmetic operation add, subtract ,divide, multiply ,inverse ,power of value ,mean ,standard deviation , if condition , for loop .
Code:
%% 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 )
= [1 2 3;43 3 4]; %% 2x3 matrix
= [3 4 2 35 5]; %% 3x2 matrix
=A*%% 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 =
  if 
x==2
      display
('x equal 2');
      
     %% 
end of if condition
  end

%% Get the size of matrix (rows ,cols)   
[
rows,cols]= size(C)  %% rows =cols=
   
%% 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
    


_________________
Currenlty programming with : java , html , php , and javascript . (OCJP-6 certified )



For this message the author msi_333 has received gratitude : codemiles
TOP
 Profile Send private message  
Reply with quote  
Post new topic Reply to topic Quick reply  [ 1 post ] 
Quick reply


  

 Similar topics
 help me How do I load image from my pc to matlab
 naive Bayes classifier in MATLAB
 error closing file matlab save
 Examples of heading tags
 Matlab SVM training problem
 MATLAB clear memory
 particle swarm optimization matlab code
 basics
 read file in matlab
 run .exe program in matlab

All times are UTC [ DST ]


Users browsing similar codes

Users browsing this forum: No registered users and 1 guest



Jump to:  
Previous Code Snippet | Next Code Snippet 




Home
General Talks
Finished Projects
Code Library
Games
Tutorials

Java
C/C++
C-sharp
php
Script
JSP/Servlets
Ajax
ASP/ASP.net
Google SEO
Database
Communications
Phpbb3 styles
Photoshop tutorials
Flash tutorials
Find a job






Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team