Error in RDA (line 235)
S(j)=sqrt(sum((stag(b).Position-Hinds(j).Position).^2));

 채택된 답변

Walter Roberson
Walter Roberson 2023년 4월 14일

0 개 추천

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

Stag(b) is 9x1 struct and Hinds(j) is 70x1 struct
If stag(b) is a 9 x 1 struct, then stag(b).Position would involve struct expansion, which would lead to "too many input arguments" for the subtraction.
I would suggest to you that stab(b) is a scalar (1 x 1) struct. And then the question is what the size of stag(b).Position and Hinds(j).Position are.
Can you please have a look at the code and let me know what could be done. Really thankful for your time.
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.
Thank you so much for your time. I was able to execute my code. Is there any way possible to reduce CPU time.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

제품

질문:

2023년 4월 14일

댓글:

2023년 4월 16일

Community Treasure Hunt

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

Start Hunting!

Translated by