フィルターのクリア

Prompt depending on another prompt

3 ビュー (過去 30 日間)
in-p
in-p 2015 年 4 月 14 日
回答済み: Guillaume 2015 年 4 月 14 日
Hi. I need a first prompt input that will determinate the size of second prompt... Ex:
1st prompt: 'Number of costumers?' (input)
2nd prompt: 'Name of costumer 1:' 'Name of costumer 2:' and so on.
Any ideas? Thanks

回答 (1 件)

Guillaume
Guillaume 2015 年 4 月 14 日
This would work:
numcustomers = input('Number of customers ?');
customers = cell{1, numcustomers);
for customeridx = 1:numcustomers
customers{customeridx} = input(sprintf('Name of customer %d:', customeridx), 's');
end
Note, however that I personally dislike prompts like this. I'd rather define a function that just take a cell array of customer names and leave it up to the user to generate that cell array, through prompt as above, or a gui, or by reading a file, or just typing the whole array at the command line.
Imagine if you have to run your script ten times, where each time just one name changes. You still have to enter all the names every time which can get a bit tedious.

カテゴリ

Help Center および File ExchangeText Data Preparation についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by