필터 지우기
필터 지우기

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