How do I create an array of scalars?

I want to make a list of the major and minor axis of several different functions. I made a loop loop that runs images from 1:10. Given, I can already get the reading of each axis, what is wrote with this code?
for j = 1:10,
...
Major_I(j,1) = regionprops(CC,'MajorAxisLength')
Minor_I(j,1) = regionprops(CC,'MinorAxisLength')
end
This loop only returns: Major_I =
10x1 struct array with fields: MajorAxisLength
Minor_I =
10x1 struct array with fields: MinorAxisLength

1 Comment

My question still hasn't been anwsered yet

Sign in to comment.

 Accepted Answer

That is because regionprops() returns a structure. Type Major_I.MajorAxisLength and Minor_I.MinorAxisLength in Command Window should give you the scalar numbers. Some of them may be empty. You can convert them to vector if you want. Something like
a=[Major_I.MajorAxisLength]
b=Minor_I.MinorAxisLength

4 Comments

Major_I(1) = []. It is creating blank Matrices for some reason.
That could happen if it does not find any regions in CC . Is CC a labeled matrix that has at least one non-zero entry? It would be worth putting in a breakpoint and examining it to be sure.
Yes, it has exactly one object. If I write the following code for one image, it returns a major and minor axis.
regionprops(CC,'MinorAxisLength')
regionprops(CC,'MajorAxisLength')
it returns: MajorAxisLength: 448.0581 and MinorAxisLength: 243.0665
What is
class(Major_I)
size(Major_I(1))
after the loop?

Sign in to comment.

More Answers (1)

Cynth
Cynth on 30 Aug 2011
I figured it out. Instead, the following code works. info = regionprops(CC, 'MinorAxisLength','MajorAxisLength'); Major_I(j) = info.MajorAxisLength; Minor_I(j) = info.MinorAxisLength;

Community Treasure Hunt

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

Start Hunting!