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

5 Ansichten (letzte 30 Tage)
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.

Akzeptierte Antwort

Stephen23
Stephen23 am 15 Feb. 2021
Bearbeitet: Stephen23 am 15 Feb. 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))

Weitere Antworten (0)

Kategorien

Mehr zu Structures finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by