Is there a way to extract specific fields from a structure?
Show older comments
I have a 1x1 structure with a large number of fields of which I'd like to extract some subset. I don't want to have to use
[myst.field1 myst.field2 myst.field3]...
Is there a way to shorten the code so I only have to type myst once and just extract the fields necessary? The structure name is nested within another structure so the code can get lengthy.
Accepted Answer
More Answers (2)
Itsik Adiv
on 3 Sep 2018
0 votes
You can use rmfield instead:
fieldsList = fieldnames(myst); myst = rmfields(myst, fieldnames{4:end});
Of course you can replace indices 4:end with any valid indexing logic you wish
Categories
Find more on Structures in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!