MATLAB Answers

convert cell to array

80 views (last 30 days)
RuiQi
RuiQi on 13 Jul 2017
Edited: Adam on 13 Jul 2017
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

  0 Comments

Sign in to comment.

Accepted Answer

Adam
Adam on 13 Jul 2017
Edited: Adam on 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.

  0 Comments

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!