why am I getting "Assignment has more non-singleton rhs dimensions than non-singleton subscripts" in this code?
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Ishvarya E
le 10 Mar 2018
Commenté : Ishvarya E
le 11 Mar 2018
for i=1:x_row ,m=1:magic_row;
for j=1:x_col , n=1:magic_col;
if(a<=c)
% t=x(i,j)+y(m,n);
if((Str(a)+x(i,j)+y(m,n))>255)
temp=x(i,j)+Str(a)+y(m,n)-256;
else
temp=x(i,j)+Str(a)+y(m,n);
end
z(i,j)=uint8(temp); %this line shows error
else
z(i,j)=uint8(x(i,j));
end
a=a+1;
end
end
2 commentaires
Stephen23
le 10 Mar 2018
@Ishvarya E: please show us the complete error message. This means all of the red text. Currently we have no idea where the error occurs.
Réponse acceptée
Walter Roberson
le 11 Mar 2018
Your lines
for i=1:x_row ,m=1:magic_row;
for j=1:x_col , n=1:magic_col;
are equivalent to
for i=1:x_row
m=1:magic_row;
for j=1:x_col
n=1:magic_col;
so your m and n are going to end up being vectors, and y(m,n) is going to be a 2D array. That leads to temp being a 2D array, but you are trying to store temp into the single location z(i,j)
There is no way in MATLAB to use a single for loop to change two variables simultaneously. Since your two variables per line appear to be different length, they appear to be varying independently, so you will probably need to go for four nested loops -- or else vectorize.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!