Dot name reference on non-scalar structure.

1 view (last 30 days)
mila boub
mila boub on 1 May 2016
Answered: Geoff Hayes on 1 May 2016
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 Comment
CS Researcher
CS Researcher on 1 May 2016
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?

Sign in to comment.

Answers (1)

Geoff Hayes
Geoff Hayes on 1 May 2016
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?

Categories

Find more on Structures in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!