How to assign different values to different variables input by the user?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
DIJESH
am 26 Mai 2014
Kommentiert: Mischa Kim
am 26 Mai 2014
prompt = 'Enter data: ';
title = 'Data input';
dlg_ans = inputdlg(prompt,title,[1 100]);
data = str2num(dlg_ans{:});
In the above program, the user is allowed to enter as many values as he wish. So how can i assign these different values to different variables automatically as they enter each value?
1 Kommentar
Akzeptierte Antwort
Mischa Kim
am 26 Mai 2014
Bearbeitet: Mischa Kim
am 26 Mai 2014
Dijesh, you could use the eval command:
prompt = 'Enter data: ';
title = 'Data input';
dlg_ans = inputdlg(prompt,title,[1 100]);
data = str2num(dlg_ans{:});
for ii=1:numel(data)
eval(sprintf('data%d = %f\n', ii, data(ii)));
end
However, as pointed out in one of your other questions I'd recommend against this approach. See this answer for reference.
2 Kommentare
Mischa Kim
am 26 Mai 2014
I just noticed that the link I posted above was not working. It is fixed now.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Data Import and Analysis finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!