Scanning folder for files and using specific function for each of them.
7 次查看(过去 30 天)
显示 更早的评论
I have two different folders with files of which names are loaded in lines 1,2. Then I want to run a function (comp.m) when an if statement is true, between the names of the two files, specifically when the name of the files contains the same date. Since the output of the function is a table(line 9), I want to create a new .csv (lines 10,11) where the name of the output file is the same as the first filename but inside a new folder output.
I use this code:
1 listSmartPhone1 = dir('SP_data/iPhone6/*.csv');
2 listSmartPhone2 = dir('SP_data/iPhone5/*.csv');
3 for i = 1:size(listSmartPhone1,1)
4 filename1 = listSmartPhone1(i,1) %First Point of Question
5 for j = 1:size(listSmartPhone2,1)
6 if [[last two digits of filename is the same as the two last digits of first filename]] %%Second Point of Question
7 filename2 = listSmartPhone2(j,1)
8 end
8 end
9 y = comp(filename1,filename2)
10 filenameOUTPUT = ('Output/filaname1') % Third Point of Question
11 writetable(y,filenameOUTPUT,'Delimiter',',','QuoteStrings',true);
12 end
1) How can I load the name of the file? See that when I write listSmartPhone1(1,1) I get this info from the image, although I just want to get
'2015-06-13_08-38-21.csv'.
2) How can I treat filenames as numbers? For example, get the number 13 (date) from filename1 and another number from filename2. 3) The output filename should be the same as listSmartPhone1 but in the Output folder.
Thanks everyone for their time.
0 个评论
采纳的回答
Thorsten
2015-7-8
1)
filename1 = listSmartPhone1(i).name;
2)
n = sscanf('2015-06-13_08-38-21.csv', '%d-%d-%d_%d-%d-%d');
3)
fullfile(OutputFolder, filename)
更多回答(0 个)
另请参阅
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!