Remove or ignore certain row while reading from text files?
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.
EDIT: Text file attached.
EDIT: The unwanted row is present in some files while in some files it is not.
4 Comments
per isakson
on 21 Jul 2016
Edited: per isakson
on 21 Jul 2016
"Without that row my script runs totally fine."   Thus, I deleted the row, which contains [7E8], and tried to read the text-file with your code. (First, I converted it to a function.) I wanted to see what you write to the Excel-file. However, that didn't work. I received
Index exceeds matrix dimensions.
Error in taskFinal (line 50)
newParameter(i) = tempSplit(2);
K>> tempSplit
tempSplit =
'1.2 OBD (OBD [8])'
K>> whos tempSplit
Name Size Bytes Class Attributes
tempSplit 1x1 146 cell
BTW: Don't use path as the name of a variable. It's the name of a Matlab function.
Proposal: Upload the resulting Excel-file to show what you want to extract.
yousaf obaid
on 22 Jul 2016
per isakson
on 22 Jul 2016
Edited: per isakson
on 23 Jul 2016
"however there is a slight change in the data in text files"   This reminds me of function I made long time ago to read a huge text file with descriptive information from a building automation system, BAS. With each revision of the BAS there was a number of changes in the text file format. The purpose of many changes was just to make the text more readable on screen. I guess, it wasn't intended to be read automatically. Eventually, I gave up to maintain the function.
Question: Do you foresee a need to maintain this script to account for changes in the file format and/or requirements to extract more information? Currently, you only read a fourth of the file.
yousaf obaid
on 25 Jul 2016
Edited: yousaf obaid
on 25 Jul 2016
Accepted Answer
More Answers (0)
Categories
Find more on Data Import and Export 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!