Azzera filtri
Azzera filtri

Assign user-input as name of variable in for loop

1 visualizzazione (ultimi 30 giorni)
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?

Risposta accettata

per isakson
per isakson il 20 Giu 2013
Modificato: per isakson il 20 Giu 2013

Più risposte (0)

Categorie

Scopri di più su Startup and Shutdown in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by