필터 지우기
필터 지우기

Assign user-input as name of variable in for loop

조회 수: 1 (최근 30일)
John
John 2013년 6월 20일
I want to write code that asks the user to open a file of data, then asks the user what they want to call it. Essentially I don't know how many files the user will have (between 2 and 10), and they all need to be distinguishable with a useful variable name.
My code first asks the user how many trials (data files) he plans to process, then runs the for loop that many times. In the for loop, it will ask the user to select the data file in question (completePath is a string of the location of the file), then prompts the user for a good variable name (TitleInput).
I want whatever TitleInput is to be assigned to the completePath string. That way those names can get assigned to graph labels, etc, automatically. Right now it simply replaces the completePath and TitleInput variables every time the for loop runs without saving previous data, so I only end up with the last file I import.
prompt = {'Enter number of trials to process'};
dlg_title = 'Trials';
num_lines = 1;
answer = inputdlg(prompt,dlg_title,num_lines);
[answer] = answer{:}; answer = str2num(answer);
for k = 1:answer
[Filename,Pathname,FilterIndex] = uigetfile('.c3d');
completePath = strcat(Pathname, Filename);
prompt = {'Name your trial'};
dlg_title = 'Trial name';
num_lines = 1;
TitleInput = inputdlg(prompt,dlg_title,num_lines);
[trialname] = TitleInput{:};
end
Help anyone?

채택된 답변

per isakson
per isakson 2013년 6월 20일
편집: per isakson 2013년 6월 20일

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by