why am I getting "Assignment has more non-singleton rhs dimensions than non-singleton subscripts" in this code?
5 次查看(过去 30 天)
显示 更早的评论
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 个评论
Stephen23
2018-3-10
@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.
采纳的回答
Walter Roberson
2018-3-11
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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!