convert cell to array

30 visualizaciones (últimos 30 días)
RuiQi
RuiQi el 13 de Jul. de 2017
Editada: Stephen23 el 12 de Ag. de 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

Respuesta aceptada

Adam
Adam el 13 de Jul. de 2017
Editada: Adam el 13 de Jul. de 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 comentario
Stephen23
Stephen23 el 12 de Ag. de 2021
Editada: Stephen23 el 12 de Ag. de 2021
Simpler and more efficient:
str2double({sp.name })

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by