Read string and numeric array in CSV file
조회 수: 1 (최근 30일)
이전 댓글 표시
Hello,
I am trying to automatize the post-processing of csv files such as the one enclosed here.
I want to extract :
- the value of Hresolution
- the four columns of data
I have tried to use readtable but I can not figure out which options to select.
Thanks for your help
댓글 수: 0
답변 (1개)
Cris LaPierre
2022년 7월 25일
If you save your file as a 'xlsx' file, you could take advantage of the 'Range' option in readtable.
Without it, you may have to be a little more creative. The approach I took was to disable a lot of the autodetection readtable uses. This approach means your files must all have the same format. Some of the 'header' values look incorrect because this approach treats them all as numeric values. Those that aren't get read in as NaN.
file = 'https://www.mathworks.com/matlabcentral/answers/uploaded_files/1076420/LDB100B.CSV';
data = readtable(file,'ReadRowNames',true,'ExpectedNumVariables',5,'PartialFieldRule','fill','numheaderlines',0)
hRes = data{'HResolution',1}
vals = data{(data{'Header Size',1}+1):end,:}
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Import and Analysis에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!