Access multiple structure fields and put them in a new structure or vector

10 vues (au cours des 30 derniers jours)
stijn L
stijn L le 15 Fév 2021
Modifié(e) : Stephen23 le 15 Fév 2021
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.

Réponse acceptée

Stephen23
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))

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