Multiple Input DIalog Box
조회 수: 2 (최근 30일)
이전 댓글 표시
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개)
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
>>
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Startup and Shutdown에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!