help with regexp

1 回表示 (過去 30 日間)
Edward
Edward 2012 年 4 月 2 日
Hi im trying to use regexp to get some 1,2 and 3 digit numbers from a string of symbols and numbers, for example:
3
2
100
so far im using regexp(string,'\d+','match') which is returning ans=['3' '2' '100'] and where:
ans(1)='3' which doesnt seem to be a number or a string.. how can i change this/these numbers to make them of some use?

採用された回答

Oleg Komarov
Oleg Komarov 2012 年 4 月 2 日
s = '32100';
out = regexp(s,'\d+','match');
cellfun(@str2double,out)
regexp returns the result in a cell array. Thus you cannot directly convert a cell that contains a string number into a proper double.
cellfun loops for each cell and applies the function specified after teh handle @
You have to acces the cell
str2double(out{1})
str2num(out{1})

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by