How to automatically get values from nx1 struct

4 ビュー (過去 30 日間)
Dries van Roovert
Dries van Roovert 2016 年 10 月 12 日
コメント済み: Dries van Roovert 2016 年 10 月 12 日
Hi Guys,
I have a nx1 struct (n keeps changing over iteration process) and I want to put the values in 1 array.
For example the array should look like this with a n=2 struct:
%Centroid = [Xcoordinate, Ycoordinate];
a(1)={'Centroid', 'Area', 'Intensity'};
a(2)={'Centroid', 'Area', 'Intensity'};
b=[a(1).Centroid
a(2).Centroid];
And I want to do this for arbitrary n (not manually as the above). Is this possible?
Thanks in advance for reading and helping.
Dries van Roovert

採用された回答

Andrei Bobrov
Andrei Bobrov 2016 年 10 月 12 日
b = [a.Centroid];
  1 件のコメント
Dries van Roovert
Dries van Roovert 2016 年 10 月 12 日
Thanks for the answer! It works.

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

その他の回答 (1 件)

Preethi
Preethi 2016 年 10 月 12 日
hi,
you can use for loop. I have attached a sample code for reference.
i=3;
b=0;
for j=1:i
a(j).name='P';
a(j).numb = j;
b=[b, a(j).numb]
end

カテゴリ

Help Center および File ExchangeStructures についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by