I need to create a nested struct from nested folders
6 次查看(过去 30 天)
显示 更早的评论
I have some folders in the following way:
Folder 1
Folder 1.1
Folder 1.1.1
img 1.1.1.1
.
.
.
img 1.1.1.36 (between 35 to 37 imgs in each folder)
Folder 1.1.2
img 1.1.2.a
.
.
.
img 1.1.2.37 (between 35 to 37 imgs in each folder)
.
.
.
.
Folder 1.1.148098
I have to combine the img files to form videos. I am trying to create nested structures so that I can access the images (img 1.1.1.1. etc. in each folder). I have tried 'dir' but it does not create nested structures. These videos will be inputs for my ML model and I don't want to use multiple for loops if I can avoid it.
Specifically (apologies if I am providing redundant explanation), I want to do something like:
for i = 1: size(Folder1.Folder1.1.Folder1.1.1.Folder 1.1.1)
image= imread(Folder1.Folder1.1.Folder1.1.1.Folder 1.1.1.img1.1.1.i)
writevideo(v, image)
end
Any help is appreciated.
0 个评论
采纳的回答
Chunru
2021-6-17
% List all the file in current folder and subfolders
fn = dir('**/*'); % structure for the information of all the file
% fn is a structure with fields:
% name: '.'
% folder: 'C:\ABCD'
% date: '01-May-2021 21:50:47'
% bytes: 0
% isdir: 1
% datenum: 7.3828e+05
% Form/sort the image filename list based on fn according to your
% requirement
% Assume fn contains the files that can be used directly
for i=1:length(fn)
if ~fn(i).isdir
current_fn = fullfile(fn(i).folder, fn(i).name);
% read file/write file
end
end
0 个评论
更多回答(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!