How to assign input given by user via inpuutdlg command to variables

1 回表示 (過去 30 日間)
Sachin Dighe
Sachin Dighe 2019 年 9 月 9 日
回答済み: Sachin Dighe 2019 年 9 月 9 日
I have used inputdlg command to get multiple user inputs. I want to assign these values to variables that is have defined.

採用された回答

Stephen23
Stephen23 2019 年 9 月 9 日
編集済み: Stephen23 2019 年 9 月 9 日
Just use indexing:
out = inputdlg(...);
somevar = out{1};
othervar = out{2};
...
  2 件のコメント
Sachin Dighe
Sachin Dighe 2019 年 9 月 9 日
Yes, values are assigned to variables but, I am getting error when I use these variables in formula. Error: undefined operator '+' for input arguments of type 'cell'
Stephen23
Stephen23 2019 年 9 月 9 日
編集済み: Stephen23 2019 年 9 月 9 日
@Sachin Dighe: inputdlg returns character vectors in a cell array, not numerics. It is not clear to me what you expect to get by using + on some cell arrays.
If you want numeric values, then you will need to convert the character vectors to numeric, e.g. using str2double or sscanf or the like:
>> out = inputdlg({'A','B'});
>> A = str2double(out(1));
>> B = str2double(out(2));
>> A+B
ans =
7.3
Note that this issue is unrelated to your original question and my answer, so it is unclear why you have unaccepted my answer (which correctly answered your question).

サインインしてコメントする。

その他の回答 (1 件)

Sachin Dighe
Sachin Dighe 2019 年 9 月 9 日
Ok thank you

カテゴリ

Help Center および File ExchangeStartup and Shutdown についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by