Multiple Input DIalog Box
3 次查看(过去 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 中查找有关 Spline Postprocessing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!