Info

Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.

create a table containing especific names of files selected from string in MATLAB

1 Ansicht (letzte 30 Tage)
Francisco
Francisco am 2 Apr. 2016
Geschlossen: MATLAB Answer Bot am 20 Aug. 2021
Hi All,
I would like to create 3 lists with the names of files starting with png, jpg and bmp. All files are images inside the directory tree: /year_month/year_month_day/ as you can see here:
./20160203/20160203_png01_test1.png.tmp
./20160203/20160203_jpg01_test2.jpg.tmp
./20160203/20160203_bmp01_test3.bmp.tmp
./20160204/20160204_png01_test1.png.tmp
./20160204/20160204_jpg01_test2.jpg.tmp
./20160204/20160204_bmp01_test3.bmp.tmp
./20160205/20160205_png01_test1.png.tmp
./20160205/20160205_jpg01_test2.jpg.tmp
./20160205/20160205_bmp01_test3.bmp.tmp
every list should contain the pictures name for every extension (jpg, bmp and png) for example list1 should have:
./20160203/20160203_png01_test1.png.tmp
./20160204/20160204_png01_test1.png.tmp
./20160205/20160205_png01_test1.png.tmp
list2 should have:
./20160203/20160203_jpg01_test2.jpg.tmp
./20160204/20160204_jpg01_test2.jpg.tmp
./20160205/20160205_jpg01_test2.jpg.tmp
and list3 the same but with bmp...
my code look like this:
workdir = '/home/mati/201602/';
cd(workdir);
command = ['find -name *test*.tmp'];
[status,cmdout] = system(command);
c = strsplit(strtrim(cmdout));
n_files = length(c);
format_id=cell(n_files,1);
for ifile =1:n_files
d = textscan(c{ifile},'%s%s', 'Delimiter','_');
s1 = d{2}{:};
format_id{ifile} = s1;
end
format_id = unique(format_id);
nformat = length(format_id);
for iformat = 1:nformat
templist = [format_id{iformat} '.dat'];
fid = fopen(templist,'w');
for ifiles =1:n_files
fprintf(fid, '%6s\n', c{iformat});
end
fid = fclose(fid);
end
but in every list I am getting all the names.
I get the lists:
png01.dat
jpg01.dat
bmp01.dat
which is fine and is what I wanted to have, but in every list I have all the names of the pictures and not only the names with the respective extension.
First I would like to make an "index" in order to select only the files with the respective extension (bmp jpg and png) and then send them to a list. How could I do that?
I hope the problem is clear. Thanks in advance for your help.

Antworten (0)

Diese Frage ist geschlossen.

Community Treasure Hunt

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

Start Hunting!

Translated by