How to read a csv file (with header + ignore some columns)

Hello,
I’m in trouble to read a csv file. Here is a sample:
,,,,,,String1[°C], String2[°C], String3[m/s], String4[°C], String5[°C], String6[°C]
,,,,,,Avg, Max, Min, Avg, Max, Min
10/04/2016, 160410 P10 – AA, Time,run1,BB,Blue,Turn1,1:50.100,11,100,25,25,55,66
10/04/2016, 160410 P10 – AA, Time,run1,BB,Blue,Turn2,1:48.680,22,99,102,56,88,77
10/04/2016, 160410 P10 – AA, Time,run1,BB,Blue,Turn3,1:49.100,55,66,123,58,55,88
10/04/2016, 160410 P10 – AA, Time,run1,BB,Blue,Turn4,1:49.080,28,33,456,59,44,99
Be careful that “Time,run1” is only one column as well as ”BB,Blue”.
I would like to get an array from this file where the first 2 lines and the first 5 columns are ignored (see below).
1:50.100 11 100 25 25 55 66
1:48.680 22 99 102 56 88 77
1:49.100 55 66 123 58 55 88
1:49.080 28 33 456 59 44 99
I tried csvread and textscan functions but I could not make it work. I don’t want to use Import Wizard function as the file will be loaded within a GUI. Could you help me?
Kind regards,
Sebastien

답변 (1개)

Walter Roberson
Walter Roberson 2016년 8월 5일

0 개 추천

textscan with the %q format specifier, if you have a new enough version of MATLAB. With older MATLAB you would need to use '"%[^"]"' instead of '%q'

댓글 수: 5

Thanks for your answer.
I still cannot make it. I tried it:
InputText = textscan(fileID,'%D%s%q%q%s%{m-ss-SSS}D%f%f%f%f%f%f','delimiter',',');
An error message appear in the command window: "Error using textscan Badly formed format string."
I aslo tried different things as %d instead of %D and so on. If I don't get the error message, InputText is a empty vector
What is wrong ?
Which version of MATLAB are you using?
Seb Seb
Seb Seb 2016년 8월 6일
편집: Stephen23 2016년 8월 7일
R2013a
And %[^"] doesn't work either
R2013a was before the %q or %D specifiers were introduced. "%[^"]" should work for the quoted strings though.
Ok, I think I'm going to try with a newer version of matLab.
Thank you for your answers.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Large Files and Big Data에 대해 자세히 알아보기

질문:

2016년 8월 5일

편집:

2016년 8월 7일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by