how can i write the code to remove the 'index exceed matrix dimension ' in matlab?

clc; clear all; close all; a=imread('cherry.jpg'); [m,n,o]=size(a); a=im2double(a); % c=zeros(m,n,o); % x=zeros(m,n); % x=double(x); % y=zeros(m,n); % y=double(y); % z=zeros(m,n); % z=double(z); for i=1:m for j=1:n x(i,j)=a(i,j,1)/(a(i,j,1)+a(i,j,2)+a(i,j,3)); y(i,j)=a(i,j,2)/(a(i,j,1)+a(i,j,2)+a(i,j,3)); z(i,j)=a(i,j,3)/(a(i,j,1)+a(i,j,2)+a(i,j,3)); end end imshow(x); figure, imshow(y); figure, imshow(z); c(:,:,1)=x; c(:,:,2)=y; c(:,:,3)=z; figure, imshow(c); p=(m/2); q=(n/2); for k=1:3 G1(1:p,1:q,k)=a(1:p,1:q,k); G2(1:p,1:q,k)=a(1:p,(q+1):n,k); G3(1:p,1:q,k)=a((p+1):m,1:q,k); G4(1:p,1:q,k)=a((p+1):m,(q+1):n,k); end figure; imshow(G1) figure; imshow(G2) figure; imshow(G3) figure; imshow(G4)
L=4; for k=1:3; s=(p*q);sum=0;La=1;Lb=1; for i=La:s+La for j=Lb:s+Lb sum=sum+x; end end end MxL=sum/s^2;
s=(p*q);sum=0;La=1;Lb=1; for i=La:s+La for j=Lb:s+Lb sum=sum+y; end end MyL=sum/s^2;
s=(p*q);sum=0;La=1;Lb=1; for i=La:s+La for j=Lb:s+Lb sum=sum+z; end end MzL=sum/s^2;
figure; imshow(MxL) figure; imshow(MyL) figure; imshow(MzL)
s=(p*q);sum=0;La=1;Lb=1; for i=La:s+La for j=Lb:s+Lb diff=x-MxL if diff>0 sum=sum+diff; else sum=sum-diff; end end end VxL=sum/s^2
s=(p*q);sum=0;La=1;Lb=1; for i=La:s+La for j=Lb:s+Lb diff=y-MyL if diff>0 sum=sum+diff; else sum=sum-diff; end end end VyL=sum/s^2
s=(p*q);sum=0;La=1;Lb=1; for i=La:s+La for j=Lb:s+Lb diff=z-MzL if diff>0 sum=sum+diff; else sum=sum-diff; end end end VzL=sum/s^2 figure; imshow(VxL) figure; imshow(VyL) figure; imshow(VzL)

1 Comment

Brrr. Unformated code and the useless debug-killer clear all, no copy of the complete error message and the failing line is not specified. "sum" is used as variable, but this shadows a built-in function with the same name.
This is not a nice question. Please enhance is substantially.

Answers (0)

This question is closed.

Asked:

on 7 Oct 2013

Closed:

Jan
on 7 Oct 2013

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!