0

I have a similar question to MATLAB CSV File Read, but slightly more complicated.

In my instance, as well as having header lines that the start of my data, the data is separated into steps all in the same file like below:

headers
1,2,3

more headers
4,5,6

more headers again
7,8,9

Is there a way to "scan" through the entire data file and output the data?

I tried with csvread;

%step 1 pre load
RNG = [23 0 1539 8];
M = csvread(dat,23,0,RNG);
%step 2 stabilisation
RNG = [1555 0 2566 8];
N = csvread(dat,1555,0,RNG);
%step 3 test
RNG = [2582 0 4693 8];
O = csvread(dat,2582,0,RNG);
%step 4 end of test
RNG = [4709 0 4920 8];
P = csvread(dat,4709,0,RNG);

but the "ranges" are slightly different between tests, so without manually checking each data file for where the data is, this approach won't work. I "experimented" with textscan but didn't get anything useful to share.

user2587726
  • 169
  • 2
  • 11
  • The ideal output to my example with 1,2,3 4,5,6, 7,8,9, would give m = 1,2,3 n = 4,5,6 o = 7,8,9, regardless of where the numerical values are in the csv file. Perhaps for one test, 7,8,9 is on line 1024, but the next test could have 7,8,9 on line 1048. – user2587726 Oct 12 '22 at 03:32
  • I guess I'm also asking, is there a way to scan through a csv file until it finds a line that has only numeric values and outputs the line number? – user2587726 Oct 12 '22 at 03:38
  • you'll likely need to read the file line by line into a cell array using a loop and `fgetl` (see the docs for an example), then parse this however you want – Wolfie Oct 12 '22 at 11:05
  • I found a way to re-output my data without the "sub headers" so this is no longer an issue for me. Will leave incase someone is interested in a proper answer. – user2587726 Oct 13 '22 at 03:25

0 Answers0