Remove or ignore a particular row while reading from text files?
1 view (last 30 days)
Show older comments
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.
0 Comments
Answers (1)
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)) = [];
See Also
Categories
Find more on Cell Arrays 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!