request user input for a number of inputs

3 views (last 30 days)
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'.

Accepted Answer

Kevin Holst
Kevin Holst on 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).
  1 Comment
Richard
Richard on 2 Mar 2012
great. I had been trying to make it work with the command inputdlg but this way seems a lot more straightforward.

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!