How to create a cell array with the content of a component of a structure?
조회 수: 1 (최근 30일)
이전 댓글 표시
I have a structure called sFiles and I want to put the information that is inside sFiles.FileName inside a cell array called your cell,
I have this code:
for i=1:1:length(sFiles)
yourcell={sFiles(i).FileName};
end
Does anybody know why is not working?
Thanks
댓글 수: 0
채택된 답변
Matt J
2020년 7월 8일
편집: Matt J
2020년 7월 8일
It is not working because in your for-loop, yourcell is never indexed by the loop variable i, so the loop code has no idea where within yourcell you want to put things.
A for-loop is, in any case, unnecessary. The whole task can be done in a single command as follows:
yourcell={sFiles.FileName};
댓글 수: 2
Matt J
2020년 7월 8일
You're quite welcome, but please Accept-click the answer to signify that your question is resolved.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Structures에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!