request user input for a number of inputs

3 Ansichten (letzte 30 Tage)
Richard
Richard am 2 Mär. 2012
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'.

Akzeptierte Antwort

Kevin Holst
Kevin Holst am 2 Mär. 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 Kommentar
Richard
Richard am 2 Mär. 2012
great. I had been trying to make it work with the command inputdlg but this way seems a lot more straightforward.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by