how to correct this for loop code?

1 vue (au cours des 30 derniers jours)
Dhines
Dhines le 18 Jan 2013
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);

Réponses (1)

Walter Roberson
Walter Roberson le 18 Jan 2013
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.

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by