subtracting a number from string
9 次查看(过去 30 天)
显示 更早的评论
how i can subtract a number from string ?
for example :
subject1_EO - i want to extract only number one..
回答(2 个)
Star Strider
2019-5-21
One approach:
str = 'subject1_EO';
nrc = regexp(str, '\d+', 'match')
nr = str2double(nrc{:})
producing:
nrc =
1×1 cell array
{'1'}
nr =
1
2 个评论
Stephen23
2019-5-21
+1 a cunning use of a comma-separated list combined with the demand-driven output of nested functions. Explicit indexing is clearer though:
nr = str2double(nrc{1})
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Cell Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!