Find a specific value(word) in csv file
조회 수: 6 (최근 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!