Reading a massive file but skipping several lines / rows at a fixed interval
Show older comments
What is the most efficient way to read / analyze rows 1-1990 of an array, then skip 9 lines, then read rows 2000-3990, skip 9 rows, read rows 4000-5990, and so on to the end of the array? Is there a way to vectorize that?
5 Comments
KSSV
on 29 Mar 2022
What information your file has?
L'O.G.
on 29 Mar 2022
L'O.G.
on 29 Mar 2022
Use a loop. Inside the loop you can easily tell MATLAB which part of the file to read, e.g.:
- TEXTSCAN lets you specify how many times the format is applied and how many header lines.
- READTABLE et al let you specify the data location, header location, etc.
What is so special about the rows you wan to ignore: are they intermediate headers or just data you don't want? The answer to that question will change how you can approach this task.
Accepted Answer
More Answers (1)
Arif Hoq
on 29 Mar 2022
try this loop:
A=(1:9990)'; % making an array
idx=2000; % taken value from 2000
count=(size(A,1)+10)/idx;
first_index=A(1:1990); % first index value to make the loop simple
C=cell(count,1);
for i=2:count
C{i}=A(idx*(i-1):(idx*i)-10);
end
mat=[C{:}]
Categories
Find more on Audio and Video Data 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!