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 で Data Type Conversion についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!