how to correct this for loop code?

조회 수: 1 (최근 30일)
Dhines
Dhines 2013년 1월 18일
for i=1:1:51
for j=1:1:51
if(i+1)>51
k=1;
else
k=i+1;
end
a1h(i,j)=A1(i,j)-A1(k,j);
end
end
%calculate vertical array
% a=input('enter the matrix');
for j=1:1:56
for i=1:1:56
if(j+1)>56
k=1;
else
k=j+1;
end
a1v(i,j)=A1(i,j)-A1(i,k);
end
end
when i run this code getting this error...
??? Attempted to access A1(52,1); index out of bounds because size(A1)=[51,56].
Error in ==> matrixupdate at 182
a1v(i,j)=A1(i,j)-A1(i,k);

답변 (1개)

Walter Roberson
Walter Roberson 2013년 1월 18일
In your first loop, you limit "i" and "j" to 51, but in the second loop you limit them to 56. If you want to work on a 51 x 56 array, limit i to 51 and limit j to 56.

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by