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 commentaire

Cynth
Cynth le 30 Août 2011
My question still hasn't been anwsered yet

Connectez-vous pour commenter.

 Réponse acceptée

Fangjun Jiang
Fangjun Jiang le 30 Août 2011
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 commentaires

Cynth
Cynth le 30 Août 2011
Major_I(1) = []. It is creating blank Matrices for some reason.
Walter Roberson
Walter Roberson le 30 Août 2011
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.
Cynth
Cynth le 30 Août 2011
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
Walter Roberson
Walter Roberson le 30 Août 2011
What is
class(Major_I)
size(Major_I(1))
after the loop?

Connectez-vous pour commenter.

Plus de réponses (1)

Cynth
Cynth le 30 Août 2011

0 votes

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!

Translated by