Subscripted assignment dimension mismatch.
4 ビュー (過去 30 日間)
古いコメントを表示
Error in RDA (line 235)
S(j)=sqrt(sum((stag(b).Position-Hinds(j).Position).^2));
0 件のコメント
採用された回答
Walter Roberson
2023 年 4 月 14 日
stag(b).Position
As outside observers, we have no idea what size of matrix that gives.
Hinds(j).Position
as outside observers, we have no idea what size of matrix that gives.
We can tell from the sum() that those values are not expected to be scalars, but they could be row vectors or they could be column vectors or they could be 2 or more dimensions. If they are 2 or more dimensions, then the sum() is only going to act over one of the dimensions, so the sum() would return a non-scalar that would not fit in the single output location.
Furthermore, if one of the Position outputs is a row vector but the other is a column vector, then the result of the subtraction would be a 2D array.
5 件のコメント
Walter Roberson
2023 年 4 月 16 日
VarSize=[model.t nVar];
That involves some values loaded from a .mat file, but it comes out as VarSize = [2 27]
RD(i).Position=unifrnd(VarMin,VarMax,VarSize);
You create random positions with size VarSize, which is 2 x 27.
S(j)=sqrt(sum((stag(b).Position-Hinds(j).Position).^2));
Both stag(b).Position and Hinds(j).Position end up 2 x 27, so subtracting them gives 2 x 27. Squaring that gives 2 x 27. sum() over an array is the summation over the first non-scalar dimension, which is the first dimension in this case. So that sum() is going to return a 1 x 27. sqrt() of a 1 x 27 is 1 x 27. So your right hand side will be 1 x 27 but your left side indicates you want to store that in a scalar.
その他の回答 (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!