Problems with Matlab Projects? You may face many Problems, but do not worry we are ready to solve your Problems. All you need to do is just leave your Comments. We will assure you that you will find a solution to your project along with future tips. On Request we will Mail you Matlab Codes for Registered Members of this site only, at free service...Follow Me.

Mean, Median , Variance, Standard deviation and Mode matlab codes


A=[10 10 20 40 60; 12 1 2 3 4; 7 8 9 11 4 ; 3 4 5 9 10];

A =

    10    10    20    40    60
    12     1     2     3     4
     7     8     9    11     4
     3     4     5     9    10


%MATLAB code to find the meanmedianvariancestandard deviation and mode for an image
...
%A=imread('pout.tif');
%Convert the image to type ‘double’.
%A=double(A);


[r,c]=size(A);

MEAN:
 The average of sum of all the values in the matrix.
%To find the mean for each column
colmean=sum(A)/r;
display(colmean);


%To calculate the mean of the matrix
totmean=sum(A(:))/(r*c);
display(totmean);


%To calculate the variance and standard-deviation column-wise
myvar=zeros([c,1]);
mystd=zeros([c,1]);
for i = 1: c
    diff=A(:,i)-colmean(i);
    myvar(i)=sum(diff.^2)/(r-1);
    mystd(i)=sqrt(myvar(i));
end

display(myvar);
display(mystd);




%To calculate the variance and standard deviation

totdiff=(A-totmean).^2;
totsum=sum(totdiff(:));
nele=(r*c)-1;
totvar=totsum/nele;
display(totvar);
totstd=sqrt(totvar);
display(totstd);





%MEDIAN



 %To find the median of the matrix row-wise
 n=r/2;
 B=sort(A,1);
 if(mod(r,2)==0)
      rowmedian=(B(round(n),:)+B(round(n)+1,:))/2;
 else
     rowmedian=B(round(n),:);
 end
 display(rowmedian);




 %To find the median of the matrix column-wise
 n=c/2;
 B=sort(A,2);
 if(mod(c,2)==0)

     colmedian=(B(:,round(n))+B(:,round(n)+1))/2;
 else
     colmedian=B(:,round(n));
 end
 display(colmedian);




%To find the total median of the image

 C=reshape(A,[],1);
 min1=min(C);
 max1=max(C);

 E=sort(A(:));
 num=round((r*c)/2);

 if( (mod(r,2)==0) || (mod(c,2)==0) )
     totmedian=(E(num)+E(num+1))/2;
    
 else
     totmedian=E(num);
 end
 display(totmedian);



    
%To find the mode of the matrix
   D=hist(C,min1:max1);
   D1=find(D==max(D));
   mymode=D1(1)+min1-1;
   display(mymode);
 


0 comments:

Post a Comment

Recent Comments

Popular Matlab Topics

Share your knowledge - help others

Crazy over Matlab Projects ? - Join Now - Follow Me

Sites U Missed to Visit ?

Related Posts Plugin for WordPress, Blogger...

Latest Articles

Special Search For Matlab Projects

MATLAB PROJECTS

counter

Bharadwaj. Powered by Blogger.