Hi,
I've tried to use the import data function for reading numeric data and text from the same CSV file. Each line of the header (first 10 lines) starts with a semicolon. The numeric data starts in row 11. That is represented in 4 columns. Sometimes there is an error message between the data rows starting with a semicolon. When I use the importdata function the data reading stops at the first error message line, though it is followed by useful data. Can anyone suggest me a way for reading in the whole file and accepting lines starting with semicolons?
THanks!

댓글 수: 1

Fangjun Jiang
Fangjun Jiang 2011년 9월 7일
Hard to tell without an example and your expected outcome.

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

 채택된 답변

Walter Roberson
Walter Roberson 2011년 9월 7일

0 개 추천

textscan() with Headerlines set to 10, and with CommentStyle set to ';'

댓글 수: 2

Laszlo Grand
Laszlo Grand 2011년 9월 7일
Sorry for my previous not detailed question. I am trying to be more specific now.
All I want to do is to delete those error lines in the data block that starts with a semicolon and overwrite the old CSV with the new data. The header must remain the same.
The header consists of 10 lines:
;Title http://www.gcdataconcepts.com X6-2mini
;Version 1148 Build num 0xF44 Build date 20110707 16:36:02 SN:CCDC22011001387
;Start_time 2011-08-18 13:27:28.144
;Switch Unknown
;Temperature 32 deg C Vbat 3937 mv
;Gain low
;SampleRate 40 Hz
;Deadband 0 counts
;DeadbandTimeout 0 sec
;Headers time Ax Ay Az
A snippet of the data section (432.000 rows, 4 columns after the header) with the error line looks like this:
1735.672 317 -10 -151
1735.694 316 -19 -154
1735.716 313 -38 -161
;1735.857504 smbus error 5
1735.88 351 -21 -169
1735.902 334 -17 -132
1735.924 288 -12 -71
Can you help me with the code that can do this?
Thanks!!!
Walter Roberson
Walter Roberson 2011년 9월 8일
filename = 'YourInput.csv';
outname = ['NEW_' filename];
infid = fopen(filename, 'rt');
outfid = fopen(outname, 'wt');
for K = 1:10
fwrite(outfid,fgets(infid));
end
while true
thisline = fgets(infid);
if ~ischar(thisline); break; end
if thisline(1) ~= ';'; fwrite(outfid, thisline); end
end
fclose(infid);
fclose(outfid);

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

추가 답변 (0개)

카테고리

도움말 센터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!

Translated by