Hi , What is exactly meant with this error message: Dot name reference on non-scalar structure. Error in (line 85)
g=min(find(particle.Best.Position==min(particle(1:nPop).Best.Position)));

댓글 수: 1

You should always provide more information to everyone. You know your entire code but we do not. Can you please share your code or at least the relevant information?

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

답변 (1개)

Geoff Hayes
Geoff Hayes 2016년 5월 1일

0 개 추천

mila - the problem is with the line of code
particle.Best.Position
particle is an array of structures where each structure has the fields Cost, Position, Best, and position. (Is this a mistake? Should this structure have two fields for position or just one?)
The field Best appears to be a structure as well with fields for Position and Cost. How are these different from the position and cost of the parent struct?
Given that particle is an array, if you are trying to access the Position from the Best struct, then you need to specify which element in the array you are trying to access. For example,
particle(1).Best.Position
will return the Position for the Best struct for the first particle. What is it that you are trying to do at this line?
You may need to re-think how you are organizing your data for each particle. How should it look? What should each particle encapsulate?
You will also have a problem with the code
particle(1:nPop).Best.Position
This will generate the error
Scalar index required for this type of multi-level indexing.
What is that you really want to extract here?

카테고리

도움말 센터File Exchange에서 Operators and Elementary Operations에 대해 자세히 알아보기

질문:

2016년 5월 1일

답변:

2016년 5월 1일

Community Treasure Hunt

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

Start Hunting!

Translated by