How do I solve this error 'Subscripted assignment dimension mismatch.'

1 回表示 (過去 30 日間)
BB BSB
BB BSB 2014 年 8 月 29 日
コメント済み: Star Strider 2014 年 8 月 29 日
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
  2 件のコメント
Andrew Reibold
Andrew Reibold 2014 年 8 月 29 日
include what line the error is on!
BB BSB
BB BSB 2014 年 8 月 29 日
The error pops up after executing ' end ' for the first loop i.e. ' for ii=1:length(aa) '

サインインしてコメントする。

採用された回答

Star Strider
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 件のコメント
BB BSB
BB BSB 2014 年 8 月 29 日
F_N is a 1x100 vector defined as F_N= ones(size(RR))*FN;
Star Strider
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 ExchangeGeneral Applications についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by