Total members 11894 |It is currently Fri Nov 22, 2024 1:39 pm Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





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
    





_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time

For this message the author DrRakha has received gratitude : codemiles
Post new topic Reply to topic  [ 1 post ] 

  Related Posts  to : Matlab basics examples
 basics     -  
 JNI Basics lesson 1     -  
 Html basics tutorials.     -  
 C++ Code Visual Basics.net 2003     -  
 Examples in C#     -  
 examples with c     -  
 few examples of c using ascii     -  
 Examples of heading tags     -  
 Asp.net insert update delete Examples     -  
 Feature selection: Statistical and Recursive examples     -  



Topic Tags

Matlab Basics






Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
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