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

1 次查看(过去 30 天)
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.

回答(1 个)

Karan Gill
Karan Gill 2016-7-8
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 个评论
yousaf obaid
yousaf obaid 2016-7-11
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?

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Cell Arrays 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by