Multiple Input DIalog Box

7 ビュー (過去 30 日間)
Saptarshi Bhattacharjee
Saptarshi Bhattacharjee 2012 年 1 月 2 日
I have a problem where I need to accept the value of a number (say n, which is incidentally the no of circles to be accepted for the problem) and depending on the value of n I need to accept 2n values into an array nx2(these will be actually the coordinates of the centers of the n circles, where each row of the matrix represents the x and y coordinate of one circle)...I want to design an input box first that will ask the user to input the value of n. Depending on the value of n entered, thereafter an input dialog should open asking for 2n center values. the dialog can be of the following form
Enter the center of 1st circle ______ _______
Enter the center of 2nd circle ______ _______
Enter the center of 3rd circle ______ _______
Enter the center of 4th circle ______ _______
Enter the center of 5th circle ______ _______
Any idea how I can design an input box for such problems??Thanks in advance
  1 件のコメント
Walter Roberson
Walter Roberson 2012 年 1 月 2 日
My email address is not an acceptable Tag.

サインインしてコメントする。

回答 (1 件)

Jose Jeremias Caballero
Jose Jeremias Caballero 2012 年 1 月 2 日
Hi.
%=======================
clear all
n=input('Enter the number of circles n:');
k=1;
while k<=n
center(k,:)=input(['Enter the center of ',num2str(k),' st circle:']);
k=k+1;
end
display(center)
x=center(:,1);
y=center(:,2);
%=============================
>> %EXECUTION
>> ncircles
Enter the number of circles n:3
Enter the center of 1st circle:[10 4]
Enter the center of 2st circle:[2 2]
Enter the center of 3st circle:[5 3]
center =
10 4
2 2
5 3
>> %EXECUTION
>> ncircles
Enter the number of circles n:5
Enter the center of 1st circle:[2 3]
Enter the center of 2st circle:[3 1]
Enter the center of 3st circle:[3 4]
Enter the center of 4st circle:[-5 6]
Enter the center of 5st circle:[10,12]
center =
2 3
3 1
3 4
-5 6
10 12
>>

カテゴリ

Help Center および File ExchangeStartup and Shutdown についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by