Borrar filtros
Borrar filtros

Assign user-input as name of variable in for loop

1 visualización (últimos 30 días)
John
John el 20 de Jun. de 2013
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?

Respuesta aceptada

per isakson
per isakson el 20 de Jun. de 2013
Editada: per isakson el 20 de Jun. de 2013

Más respuestas (0)

Categorías

Más información sobre Startup and Shutdown en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by