MATLAB: Accessing Values From Structure or Cell Aray

cell araystruct

Hey Guyz..
I am here with another question,The problem I am facing is the accessing and utilizing the data stored in cell Array or Struct. The Project I am currently working on the calculation of centroid values stored in the struct.
I want to create a function that receives from desired struct,uses the point distance formula and calculate the distances for each and every centroid distances of whole image. I have also attached the image of that struct values….
Thanks in Advance !!!!

Best Answer

centroidVals = sscanf( g(i).Centroid, '[%f,%f]' )
will give you the i centroid as just a pair of doubles.
Your struct array only has one field so I assume you mean the first two elements of the array rather than fields 1 and 2.
centroidVals = sscanf( g(1:2).Centroid, '[%f,%f]' )
centroidVals = sscanf( g.Centroid, '[%f,%f]' )
will give you the first two centroid values or all centroid values (respectively).
The result will be in a vector list, each centroid starting at an odd index, but it can easily be reshaped or manipulated into another format.
Related Question