convert cell to array

39 Ansichten (letzte 30 Tage)
RuiQi
RuiQi am 13 Jul. 2017
Bearbeitet: Stephen23 am 12 Aug. 2021
I have a structure sp. How can I copy the content name into an arrray ? Its supposed to be an array of numbers.
a = sp.name;
a = sp(:).name;
does not work

Akzeptierte Antwort

Adam
Adam am 13 Jul. 2017
Bearbeitet: Adam am 13 Jul. 2017
names = { sp.Name }
will extract them into a single cell array
nums = cellfun( @str2double, names );
will turn them to a numeric array. Or just
cellfun( @str2double, { sp.Name } )
as a one-line command.
  1 Kommentar
Stephen23
Stephen23 am 12 Aug. 2021
Bearbeitet: Stephen23 am 12 Aug. 2021
Simpler and more efficient:
str2double({sp.name })

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Cell Arrays finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by