Assign user-input as name of variable in for loop

1 次查看(过去 30 天)
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