Dot name reference on non-scalar structure.

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 个)

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 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by