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

 Réponse acceptée

Adam
Adam le 13 Juil 2017
Modifié(e) : Adam le 13 Juil 2017

1 vote

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 commentaire

Stephen23
Stephen23 le 12 Août 2021
Modifié(e) : Stephen23 le 12 Août 2021
Simpler and more efficient:
str2double({sp.name })

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by