How do I solve this error 'Subscripted assignment dimension mismatch.'
2 次查看(过去 30 天)
显示 更早的评论
Hi, guys please can someone help me resolve why the below code returns the above mentioned error.
N = 100;
z1 = zeros(1,N);
z = meshgrid(z1);
p = meshgrid(z1);
for ii=1:length(aa)
xn=linspace(-aa(ii),aa(ii),N); yn=linspace(-bb(ii),bb(ii),N);
for i=1:length(xn)
for j=1:length(yn)
z(i,j) = (1 - (xn(i)/aa(ii))^2 - (yn(j)/bb(ii))^2);
if z(i,j)<0
z(i,j)=0;
end
p(i,j) = 1.5.*F_N.*(pi*aa(ii)*bb(ii))^-1*sqrt(z(i,j));
end
end
end
采纳的回答
Star Strider
2014-8-29
I’m guessing this line is throwing the error and it is because ‘F_N’ isn’t a scalar:
p(i,j) = 1.5.*F_N.*(pi*aa(ii)*bb(ii))^-1*sqrt(z(i,j));
2 个评论
Star Strider
2014-8-29
That’s the reason you’re getting the error. Change ‘p’ to:
p(i,j,:) = 1.5.*F_N.*(pi*aa(ii)*bb(ii))^-1*sqrt(z(i,j));
(a three-dimensional matrix) to accommodate ‘F_N’ as a vector, or change ‘F_N’ to ‘FN’ to keep it as a two-dimensional matrix (your current p(i,j)). Either will stop the line from throwing the error. Your choice.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!