How to create a cell array with the content of a component of a structure?

조회 수: 2 (최근 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

채택된 답변

Matt J
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};

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by