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 CenterFile Exchange 中查找有关 Text Data Preparation 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by