request user input for a number of inputs

1 回表示 (過去 30 日間)
Richard
Richard 2012 年 3 月 2 日
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 Center および File ExchangeLogical についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by