How to automatically get values from nx1 struct

5 Ansichten (letzte 30 Tage)
Dries van Roovert
Dries van Roovert am 12 Okt. 2016
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

Akzeptierte Antwort

Andrei Bobrov
Andrei Bobrov am 12 Okt. 2016
b = [a.Centroid];

Weitere Antworten (1)

Preethi
Preethi am 12 Okt. 2016
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

Kategorien

Mehr zu Structures finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by