Define a variable via inputdlg?

조회 수: 6 (최근 30일)
Mark
Mark 2014년 1월 30일
댓글: Mark 2014년 1월 31일
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일
row = inputdlg('Insert row number.');
row = str2num(row{:});
  댓글 수: 3
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일
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Cell Arrays에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by