how can i get a number from a string.
12 ビュー (過去 30 日間)
古いコメントを表示
i have a string 'index_N=10' in a file.
how can i get only number 10 from this string
0 件のコメント
回答 (3 件)
KSSV
2016 年 10 月 25 日
str = 'index_N=10' ;
idx = strfind(str,'=') ;
n = str2num(str(idx+1:end))
There are many other ways too.
Note: If you find the answer useful, accept the answer. you have asked many questions and so far not accepted any answer.
0 件のコメント
Andrei Bobrov
2016 年 10 月 25 日
編集済み: Andrei Bobrov
2016 年 10 月 25 日
str = 'index_N=10';
out = str2double(regexp(str,'\d*','match'));
0 件のコメント
Ganesh Hegade
2016 年 10 月 25 日
HI,
Suppose A = 'index_N=10', then you can get value of index_N by using
eval(A);
it gives index_N = 10 as output.
else you can use
regexp(A, '\d*', 'match')
it writes output 10 in a cell.
Thanks.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Characters and Strings についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!