how to automatically open files and do the commands
5 次查看(过去 30 天)
显示 更早的评论
You know how in a simple macro software, I give command such as
"click window explore(directory where the data are saved) -> arrow down(to select the next data file) -> enter(open file) -> do what u gotta do -> save & exit"
so that the macro opens the files below the one before over and over....
How do i set the command such as above in matlab?
I have files that has inconsistent file names, such as 1.txt, 1.2.txt, 2.txt, 10.txt, 21.txt....
0 个评论
采纳的回答
jgg
2016-1-26
You'll have to program this, but it's pretty straightforward.
cd 'C:\Users\etc' %your file path with all the files.
c = struct2cell(dir('*.txt')); %get a listing of all the files with extension .txt in the directory
for i = 1:size(l,1)
fileID = fopen(c{1,i});
doWhatUGottaDo(fileID);
end
The cell{1,i} contains the name of the file, which you can then use to open it and do stuff to it. How you proceed from here depends on what you want to do.
5 个评论
Image Analyst
2016-1-27
Or you could have used the simpler way in the FAQ, which avoids cell arrays altogether and just uses the simple structure array returned by dir(). I see no need to stuff it into a cell array when you can get the filename simply and directly from the structure. It just makes it more complicated for no reason/benefit.
更多回答(1 个)
Image Analyst
2016-1-26
It's one of the most FA'd FAQ: http://matlab.wikia.com/wiki/FAQ#How_can_I_process_a_sequence_of_files.3F
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Startup and Shutdown 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!