Prompt depending on another prompt

1 visualización (últimos 30 días)
in-p
in-p el 14 de Abr. de 2015
Respondida: Guillaume el 14 de Abr. de 2015
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

Respuestas (1)

Guillaume
Guillaume el 14 de Abr. de 2015
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.

Categorías

Más información sobre Environment and Settings en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by