How do I change File Name Variable within a Loop
94 次查看(过去 30 天)
显示 更早的评论
Looked at sprintf() and did not understand it. Keep it simple, I do not understand code, this is for a uni assignment, prof expects us to "just google it" when we run into issues
Trying to load 12 files. Names are "Ss_R_L.mat" where
s is a number between 1 and 3
R is either "Walk" or "Run"
L is either "90PSL" or "PSL"
for R = 1:2
if R == 1
% use "Walk"
else
% use "Run"
end
for L = 1:2
if L == 1
% use "PSL"
else
% use "90PSL"
end
for S = 1:3
if S == 1
load('S1_R_L.mat')
elseif S == 2
load('S2_R_L.mat')
else
load('S3_R_L.mat')
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Plotting Data from the Files %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
end
end
end
0 个评论
采纳的回答
Hiroki Okawa
2020-2-21
for R = 1:2
if R == 1
txt_R = 'Walk';
else
txt_R = 'Run';
end
for L = 1:2
if L == 1
txt_L = 'PSL';
else
txt_L = '90PSL';
end
for S = 1:3
filename = ['S', num2str(S), '_', txt_R, '_', txt_L, '.mat']
load(filename)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Plotting Data from the Files %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
end
end
end
or
Rs = {'Walk', 'Run'};
Ls = {'PSL', '90PSL'};
for r = 1 : 2
for l = 1 : 2
for s = 1 : 3
filename = ['S', num2str(s), '_', Rs{r}, '_', Ls{l}, '.mat']
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Plotting Data from the Files %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
end
end
end
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Google 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!