vertically concatenate struct values from the same field

3 Ansichten (letzte 30 Tage)
Rupeng Li
Rupeng Li am 27 Jul. 2020
Bearbeitet: Stephen23 am 23 Feb. 2022
Hi I encountered an issue in vertically concatenation of struct values from the same field. e.g. given S1
[S1(1:10).vals] = deal([1,2,3])
what I want to achieve is to extract all values from the field 'vals' of struct 'S1'. I could do it in a for loop so that
t= [];
for i = 1: 10
t = [t;S1(i).vals];
end
Since such commands appears frequently, is there a neater code for this purposes using structfun?
Any suggestion would be appreciated!

Akzeptierte Antwort

Stephen23
Stephen23 am 27 Jul. 2020
Bearbeitet: Stephen23 am 23 Feb. 2022
  1 Kommentar
Rupeng Li
Rupeng Li am 27 Jul. 2020
Bearbeitet: Rupeng Li am 27 Jul. 2020
Thanks! that's very neat. Also thanks for your supplementary materials. The comma seperated list looks powerful.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Structures finden Sie in Help Center und File Exchange

Produkte


Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by