필터 지우기
필터 지우기

I need to create a nested struct from nested folders

조회 수: 6 (최근 30일)
Debasmita Mukherjee
Debasmita Mukherjee 2021년 6월 17일
답변: Chunru 2021년 6월 17일
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.

채택된 답변

Chunru
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개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by