Find a specific value(word) in csv file
4 次查看(过去 30 天)
显示 更早的评论
In this csv file
I want to extract specific section(ex.2022) in Part 1 and "D" value(ex.1) in Part 2
Finally I want to extract it
2022 1
2021 2
2020 3
2019 4
2018 5
0 个评论
回答(1 个)
Voss
2022-7-16
编辑:Voss
2022-7-16
C = readcell('table_data (1).csv', ...
'Delimiter','\t', ...
'NumHeaderLines',1)
years = regexp(C(:,1),'/(\d{4})','tokens','once');
years = vertcat(years{:})
d = regexp(C(:,2),'"D":"(\d+)"','tokens','once');
d = vertcat(d{:})
% result as a cell array of character vectors:
result = [years d]
% or, result as a numeric matrix:
result = str2double([years d])
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 String Parsing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!