how can i get a number from a string.

19 Ansichten (letzte 30 Tage)
lafnath p
lafnath p am 25 Okt. 2016
Beantwortet: Ganesh Hegade am 25 Okt. 2016
i have a string 'index_N=10' in a file.
how can i get only number 10 from this string

Antworten (3)

KSSV am 25 Okt. 2016
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.

Andrei Bobrov
Andrei Bobrov am 25 Okt. 2016
Bearbeitet: Andrei Bobrov am 25 Okt. 2016
str = 'index_N=10';
out = str2double(regexp(str,'\d*','match'));

Ganesh Hegade
Ganesh Hegade am 25 Okt. 2016
Suppose A = 'index_N=10', then you can get value of index_N by using
it gives index_N = 10 as output.
else you can use
regexp(A, '\d*', 'match')
it writes output 10 in a cell.

Community Treasure Hunt

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

Start Hunting!

Translated by