How to pull an item and save it into an array/matrix from a Cell that is composed of a Struct
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
nas illmatic
le 17 Oct 2015
Réponse apportée : nas illmatic
le 18 Oct 2015
I have a myVar which is a 1x27 Cell, where each Cell is a Struct. Within the Struct is a Field called myPullItem that I want to grab. However 'pull' with a '(i)' afterwards to increment the array produces an error; when I remove the (i), it only provides me the last cell's Struct myPullItem
for i=1:length(myVar)
pull(i) = myVar{i}.myStruct.myPullItem
end
Error: In an assignment A(:) = B, the number of elements in A and B must be the same.
My objective is to save each field. I am attempting to do this by incrementing through each cell of Structs and saving it.
What am I doing wrong? Thx.
0 commentaires
Réponse acceptée
Plus de réponses (2)
James Tursa
le 18 Oct 2015
Modifié(e) : James Tursa
le 18 Oct 2015
pull(i) is likely a scalar, while myVar{i}.myStruct.myPullItem is likely not a scalar. You are trying to stuff multiple values into a scalar, hence the error.
What is myVar{i}.myStruct.myPullItem? Once we know the size we can offer suggestions (e.g., using another cell array, or perhaps an nD array, etc). E.g., something like this:
pull{i} = myVar{i}.myStruct.myPullItem;
or maybe this:
pull(:,:,i) = myVar{i}.myStruct.myPullItem;
Again, can't tell for sure what will work for you until we know what the rhs is.
0 commentaires
Voir également
Catégories
En savoir plus sur Variables dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!