Access multiple structure fields and put them in a new structure or vector
10 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I have a cell structure with below layout. In below example I acces a single field.
dataArray{1,(2)}(1,1)
Is there a way to acces multiple fields and get them into a new structure or a vector without using a for loop?
E.g. dataArray{1,(2:10)}(1,1)
I'm afraid I use the brackets in a wrong way.
0 commentaires
Réponse acceptée
Stephen23
le 15 Fév 2021
Modifié(e) : Stephen23
le 15 Fév 2021
No, what you are asking for is not possible. This syntax:
dataArray{1,2:10}
creates a comma-separated list of separate arrays, which cannot be further indexed into using one pair of parentheses as your example shows.
You can use parentheses (as opposed to curly braces) to return that part of the cell array:
sub = dataArray(1,2:10)
You could use that together with cellfun to return the first element of each of those cells:
out = cellfun(@(a)a(1,1),dataArray(1,2:10))
0 commentaires
Plus de réponses (0)
Voir également
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!