How to extract a number from a string array?
显示 更早的评论
4 个评论
Dayne Coleman
2018-6-21
编辑:Dayne Coleman
2018-6-21
Juan Fernandez
2018-6-21
编辑:Juan Fernandez
2018-6-21
Have you looked through the documentation page for the sscanf(_) function? That might provide you a solution.
Dayne Coleman
2018-6-21
Dayne Coleman
2018-6-21
采纳的回答
更多回答(1 个)
Juan Fernandez
2018-6-21
I searched through older questions and found a similar one from 2012. The solution requires the use of regexp(_). Here's my implementation.
str1 = '(164) - (165)';
str2 = '(165) - (166)';
str3 = '(165) - (166)';
strs = {str1,str2,str3};
output = zeros(length(strs),1);
for iter=1:length(strs)
num_strs = regexp(strs{iter},'\d*','Match');
output(iter) = str2double(num_strs{1});
end
类别
在 帮助中心 和 File Exchange 中查找有关 Characters and Strings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!