Remove or ignore a particular row while reading from text files?

2 views (last 30 days)
Hello. I have a number of text files in different subfolders which are in one main folder. My task was to read all the text files, convert all the read information in a particular format into a cell array and then write the cell array to an excel sheet.
The task is completely done, however there is a slight change in the data in text files. The new files that i have gotten have one extra row. Without that row my script runs totally fine. But with the new row added, i get this error;
Subscript indices must either be real positive
integers or logicals.
Error in taskFinal (line 52)
newPDU(i) = newPDU(i-1);
What I need is a little help regarding how to deal with this useless row.
The row number is 37 in the files. What I need is that while reading the data from the text files, either we ignore that row or also simply remove the line from the cell array when the data from the file is read into the cell array. There is only one word in that row which is " [7E8] ". The m-file and one text file is attached below.
Thank you for any kind of help.

Answers (1)

Karan Gill
Karan Gill on 8 Jul 2016
Could you find all elements of Cstr with '[7E8]' and delete them?
Cstr = textread(file2{i2}, '%s', 'delimiter', '');
idx = strfind(cString,'[7E8]');
Cstr(~isempty(idx)) = [];
  1 Comment
yousaf obaid
yousaf obaid on 11 Jul 2016
hello. Thank you for your time, however when i tried to delete '[7E8]', it gave an error
Error using strfind
Input strings must have one row.
Error in taskFinal (line 28)
idx = strfind(cString,'[7E8]');
there is this one thing, the E in '[7E8]' is not the capital E, its a comparatively small E. Do you think matlab read it as capital E and gave this error?

Sign in to comment.

Categories

Find more on Characters and Strings in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!