request user input for a number of inputs

3 次查看(过去 30 天)
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'.

采纳的回答

Kevin Holst
Kevin Holst 2012-3-2
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 个评论
Richard
Richard 2012-3-2
great. I had been trying to make it work with the command inputdlg but this way seems a lot more straightforward.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by