vertically concatenate struct values from the same field

3 vues (au cours des 30 derniers jours)
Rupeng Li
Rupeng Li le 27 Juil 2020
Modifié(e) : Stephen23 le 23 Fév 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!

Réponse acceptée

Stephen23
Stephen23 le 27 Juil 2020
Modifié(e) : Stephen23 le 23 Fév 2022
  1 commentaire
Rupeng Li
Rupeng Li le 27 Juil 2020
Modifié(e) : Rupeng Li le 27 Juil 2020
Thanks! that's very neat. Also thanks for your supplementary materials. The comma seperated list looks powerful.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Structures dans Help Center et File Exchange

Produits


Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by