How do I change File Name Variable within a Loop

94 ビュー (過去 30 日間)
Emily Dueck
Emily Dueck 2020 年 2 月 21 日
編集済み: Emily Dueck 2020 年 2 月 21 日
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

採用された回答

Hiroki Okawa
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
  1 件のコメント
Emily Dueck
Emily Dueck 2020 年 2 月 21 日
You are a lifesaver

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGoogle についてさらに検索

製品


リリース

R2019a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by