필터 지우기
필터 지우기

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 View and Analyze Simulation Results에 대해 자세히 알아보기

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by