Simple string to number help; how to convert this into a number?

I'm not sure how I would convert the string into a number for this part of my program;
H1 = inputdlg('Number of rows');
%not sure how to get H1 to a number
if H1 <=0
H1 = inputdlg('Positive number of rows');
else
numRows = (H1);
end
*Undefined function 'le' for input arguments of type 'cell'.*
trying to get H1 as a positive number but this error keeps showing up because it is a string

 採用された回答

Hikaru
Hikaru 2015 年 2 月 25 日
編集済み: Hikaru 2015 年 2 月 25 日

0 投票

Assuming that H1 contains only one value, you could use
n = H1{1} % to access that value in the cell
if c <=0
c = inputdlg('Positive number of rows');
else
numRows = (c); %note that numRows is stored as 'char'
end
On a side note, is it really necessary to use inputdlg? You could store it as a double if you had use input instead.
H1 = input('Number of rows: ')

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeCharacters and Strings についてさらに検索

質問済み:

2015 年 2 月 25 日

編集済み:

2015 年 2 月 25 日

Community Treasure Hunt

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

Start Hunting!

Translated by