How to assign different values to different variables input by the user?
조회 수: 1 (최근 30일)
이전 댓글 표시
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?
채택된 답변
Mischa Kim
2014년 5월 26일
편집: Mischa Kim
2014년 5월 26일
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
Mischa Kim
2014년 5월 26일
I just noticed that the link I posted above was not working. It is fixed now.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Import and Analysis에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!