Define a variable via inputdlg?

I would like a variable to be assigned via a user prompt. For example, consider the following command:
row = inputdlg('Insert row number.');
When a user inputs 1 in the popup box, the value of the variable "row" is not recognized as a number or a string, but as a '1', with ticks surrounding it.
Is there a way to have a variable defined as a number or a string from a popup box?
Thank you!

 採用された回答

Amit
Amit 2014 年 1 月 30 日

0 投票

row = inputdlg('Insert row number.');
row = str2num(row{:});

3 件のコメント

Mark
Mark 2014 年 1 月 30 日
I'm sorry, I could have been clearer. "row" refers to a row of grapevines in a vineyard for my program. It's just a variable, not a row in a matrix...
I'd like to define a number variable via a user input in a popup box. Thanks!
Amit
Amit 2014 年 1 月 30 日
That's correct and that's what this will do (give it a try). You can replace row with whatever variable name you like.
Moreover, row is not a matlab command that you'll override by using as a variable !
Mark
Mark 2014 年 1 月 31 日
Thank you! Works like a charm :)

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

その他の回答 (1 件)

David Sanchez
David Sanchez 2014 年 1 月 30 日

1 投票

You can do it in a single line and use str2double which is faster than str2num:
row = str2double( inputdlg('Insert row number.') );

1 件のコメント

Mark
Mark 2014 年 1 月 31 日
Excellent! Problem solved, thank you.

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

カテゴリ

ヘルプ センター および File ExchangeData Type Conversion についてさらに検索

タグ

質問済み:

2014 年 1 月 30 日

コメント済み:

2014 年 1 月 31 日

Community Treasure Hunt

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

Start Hunting!

Translated by