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

cell arraysstructure

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)
Does anybody know why is not working?

Best Answer

  • 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: