request user input for a number of inputs
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
At the start of one of my scripts I would like to use the input command for the user to specify some values for a given location. For example, if I have four locations:
Location = {'Loc1','Loc2','Loc3','Loca4'};
I would like matlab to display these individually on the screen and ask the user for some input for each location. I would like the user to input surface area and depth of each Location.
So, at the beginning of the script I need matlab to display:
Loc1: Area ... Depth...
Where the user would then type the Area and the depth for that given location. Ideally the values would then be stored in a cell array, one for the area and another for the Depth where the first cells should correspond to the first cell in 'Location'.
0 commentaires
Réponse acceptée
Kevin Holst
le 2 Mar 2012
There are several ways to do this, but if you're wanting cell arrays, I'd do something like this:
for i = 1:length(Location) % this allows for different size location arrays
area{i} = input(['Input area for Location ' num2str(i) ': ']);
depth{i} = input(['Input depth for Location ' num2str(i) ': ']);
end
That will get you all you need, however it won't ensure that the proper type of data is input into those arrays. You may want to run some checks in there to ensure that the inputs are numbers and valid values (ie not negative).
Plus de réponses (0)
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!