How to iterate through a struct ?

112 views (last 30 days)
RuiQi
RuiQi on 9 Nov 2018
Edited: Matt J on 9 Nov 2018
How can i iterate through a struct in matlab ? Here is my code that does not work
im_filenames = dir('./JAAD_frames/video_0001/');
for name,foldername in im_filenames:
print(name, foldername)

Answers (2)

Image Analyst
Image Analyst on 9 Nov 2018
Try this:
filesStructure = dir('./JAAD_frames/video_0001/*.*')
allFileNames = {filesStructure(:).name}
for k = 1 : length(allFileNames)
fprintf('allFileNames{%d} = %s\n', k, allFileNames{k});
end

Matt J
Matt J on 9 Nov 2018
Edited: Matt J on 9 Nov 2018
for i=1:numel(im_filenames)
print(im_filenames.name, im_filenames.folder)
end
  2 Comments
Matt J
Matt J on 9 Nov 2018
Edited: Matt J on 9 Nov 2018
It's nothing to do with the loop. Use dir() to get only the folder contents that are file names.

Sign in to comment.

Categories

Find more on Develop Apps Using App Designer in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by