How to have a changing variable within a user input?
11 ビュー (過去 30 日間)
古いコメントを表示
I have the user input a number from 1-100. Here is the segment of my file that I'm working with.
Num = input('How many circles? ');
disp('Now enter the diameter of each circle one at a time when prompted')
for i=1:Num
D(:,i)= input('Diameter of circle ___ in mm: ')
end
I want the user to see "Diameter of circle 1 in mm? then "Diameter of circle 2 in mm? then "Diameter of circle 3 in mm? and so on until they have input the diameters for all of the circles.
I have tried to use num2str(i) but I haven't been able to get that to work. Later on I use num2str(i) within a disp text and that works fine. Any thoughts?
0 件のコメント
採用された回答
Andrei Bobrov
2012 年 8 月 9 日
Num = input('How many circles? ');
disp('Now enter the diameter of each circle one at a time when prompted')
D = zeros(Num,1);
for i=1:Num
D(i)= input(['Diameter of circle ',num2str(i),' in mm: ']);
end
0 件のコメント
その他の回答 (1 件)
Daniel Shub
2012 年 8 月 9 日
Not sure how you tried to use num2str, but
D(:,i)= input(['Diameter of circle ', num2str(i), ' in mm: '])
works for me
参考
カテゴリ
Help Center および File Exchange で Tables についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!