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

 채택된 답변

Adam
Adam 2017년 7월 13일
편집: Adam 2017년 7월 13일

1 개 추천

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

Stephen23
Stephen23 2021년 8월 12일
편집: Stephen23 2021년 8월 12일
Simpler and more efficient:
str2double({sp.name })

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Data Type Conversion에 대해 자세히 알아보기

태그

질문:

2017년 7월 13일

편집:

2021년 8월 12일

Community Treasure Hunt

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

Start Hunting!

Translated by