How to add an array in a structure as a new field?

19 ビュー (過去 30 日間)
Nut
Nut 2016 年 7 月 29 日
コメント済み: Nut 2016 年 8 月 1 日
Hi,
I'm using the following code to get a structure variable stats, that will have 23 + 1 = 24 fields.
stats = regionprops(bw,'All');
[labeled, nObject] = bwlabel(bw);
for i = 1:nObject
stats(i).Ratio = stats(i).MinorAxisLength/stats(i).MajorAxisLength;
end
The for loop is too slow, because I'm dealing with a huge number of regions, and I have to speed up my code. I tried with this line:
stats(:).AxisRatio=[stats.MinorAxisLength]'./[stats.MajorAxisLength]';
and many others, with no success.
Therefore, is there a way to add the 24th field to the structure more rapidly? In other words, I need the reverse operation than:
prop_array = [struct.prop_field]';
Thanks for your answers.

採用された回答

James Tursa
James Tursa 2016 年 7 月 29 日
E.g.,
c = num2cell([stats.MinorAxisLength]./[stats.MajorAxisLength]);
[stats.Ratio] = c{:};
  1 件のコメント
Nut
Nut 2016 年 8 月 1 日
Absolutely perfect! Thank you very much!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeImage Processing and Computer Vision についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by