code to run multiple times in for loop
2 次查看(过去 30 天)
显示 更早的评论
i want to run the following code in for loop for n number of time say for eg 100. i have around 100 mat files in the folder.
filename='path name'
str=whos('-file',filename)
str={str.name}
load(filename,str{:})
0 个评论
采纳的回答
Mathieu NOE
2021-10-28
hello
I guess you want something like that... here it's for laoding excel file but you can easily adapt it for mat files
if you want to load in natural sorting , you need also to retrieve natsortfiles from FEX :
clc
clearvars
fileDir = pwd;
outfile = 'OUT.xlsx'; % output file name
fileNames = dir(fullfile(fileDir,'data*.xlsx')); % get list of data files in directory
fileNames_sorted = natsortfiles({fileNames.name}); % sort file names into natural order (https://fr.mathworks.com/matlabcentral/fileexchange/47434-natural-order-filename-sort)
M= length (fileNames_sorted);
out_data = [];
for f = 1:M
% option # 1 for numeric data only using importdata
raw = importdata( fullfile(fileDir, fileNames_sorted{f}));
% vertical contatenation of all individual files data
out_data = [out_data; raw.data];
end
% store out_data in excel file
writematrix(out_data,fullfile(fileDir,outfile));
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spreadsheets 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!