Storing a struct in a cell

33 vues (au cours des 30 derniers jours)
Hailey Trier
Hailey Trier le 17 Avr 2017
Commenté : Hailey Trier le 17 Avr 2017
Hi, I am trying to create a 1x30 cell in which each cell contains a structure. My code so far is as follows:
groupavg = cell(1,30);
for i = 1:30
groupavg(:,i) = averages.timelock.(subject{i});
end
The error I get when I run this is "Conversion to cell from struct is not possible." When I use the function struct2cell I receive the error "Assignment has more non-singleton rhs dimensions than non-singleton subscripts."
I am trying to emulate some imported data that is a 1x10 cell with each cell filled by a 1x1 struct that has 7 fields, so I know this is possible but I'm not sure where I'm going wrong with storing the structure. Any help is appreciated.

Réponse acceptée

Andrew Newell
Andrew Newell le 17 Avr 2017
Try curly brackets:
groupavg{:,i} = averages.timelock.(subject{i});
This places the RHS inside the cell element instead of trying to replace the cell element by a structure.
  1 commentaire
Hailey Trier
Hailey Trier le 17 Avr 2017
Thanks!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Structures dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by