How to write in short form?
2 次查看(过去 30 天)
显示 更早的评论
Greetings,
How can I write the following command in a short form to avoid this repetition?
clear
%%load all Residual .mat files
s = what; %look in current directory
%s=what('dir') %change dir for your directory name
matfiles=s.mat
for a=1:numel(matfiles)
load(char(matfiles(a)))
end
SDED = vertcat(SDED1,SDED2,SDED3,SDED4,SDED5,SDED6, ...
SDED7,SDED8,SDED9,SDED10,SDED11,SDED12);
save SDED.mat SDED
Thank you for the help
0 个评论
采纳的回答
更多回答(1 个)
Thorsten
2015-10-28
编辑:Thorsten
2015-10-28
If you know that the SDED are numbered from 1 to 12:
s = sprintf('SDED%d, ', 1:12);
eval(['SDED = vertcat(' s(1:end-2) ');'])
or if you want to use all SDED variables in the workspace:
x = whos('SDED*');
s = sprintf('%s, ', x.name);
eval(['SDED = vertcat(' s(1:end-2) ');'])
2 个评论
Stephen23
2015-10-28
Better to avoid eval and simply load the data into one structure:
S = load(...);
Why eval is poor code that should be avoided:
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 File Operations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!