필터 지우기
필터 지우기

How do i manage the number of input dialog box according to the user's choice?

조회 수: 1 (최근 30일)
Suppose the program is to find average of the numbers given by the user. The first step would be to create a dialog box to ask the user the number of numbers to be input. Second step would be to prompt dialog boxes where the user will enter the numbers. Now, here the number of dialog boxes prompted must be equal to the number input by the user in the 1st step. How do I manage the number of prompts?

채택된 답변

Mischa Kim
Mischa Kim 2014년 5월 23일
DIJESH, you could use something like
prompt = 'Enter data: ';
title = 'Data input';
dlg_ans = inputdlg(prompt,title,[1 100]);
data = str2num(dlg_ans{:});
where the user would enter numbers (separated by empty spaces) and thereby avoiding a second input dialog.
  댓글 수: 4
Mischa Kim
Mischa Kim 2014년 5월 23일
편집: Mischa Kim 2014년 5월 23일
It depends what you need to do. With the above approach you can access the individual values as components of the array (e.g. data(1)). In general I would advise against using n different variable names and rather go with arrays.
DIJESH
DIJESH 2014년 5월 23일
in the project which i am working on it is necessary to ask any number of forces from the user and then assign it to different variables so that it can be be split into its horizontal and vertical component. If the user inserts 100 forces and their angles, the program will have to seperate out the components of those 100 forces .....

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by