How to iterate through a struct ?

29 ビュー (過去 30 日間)
RuiQi
RuiQi 2018 年 11 月 9 日
編集済み: Matt J 2018 年 11 月 9 日
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)

回答 (2 件)

Image Analyst
Image Analyst 2018 年 11 月 9 日
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 2018 年 11 月 9 日
編集済み: Matt J 2018 年 11 月 9 日
for i=1:numel(im_filenames)
print(im_filenames.name, im_filenames.folder)
end
  2 件のコメント
RuiQi
RuiQi 2018 年 11 月 9 日
Very clean solution but I get this error
Error using inputcheck
Multiple inputs that look like file names: '.' and '..'.
Error in print (line 41)
[pj, devices, options ] = inputcheck( pj, inputargs{:} );
Error in untitled (line 6)
print(im_filenames.name, im_filenames.folder)
Matt J
Matt J 2018 年 11 月 9 日
編集済み: Matt J 2018 年 11 月 9 日
It's nothing to do with the loop. Use dir() to get only the folder contents that are file names.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeStructures についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by