MATLAB: How to read data after a specific string

datareadtext;

I have three sets of data: raw, average, and median. They are all in different .txt files and have 1024 data points with its x, y, z, etc.
Now I'm trying to get the data into the workspace so I can run some analysis on it but I don't know how to make a code work for the three different sets. They all start with machine and measurement specifications like date, voltage, scaling, etc. for 30-60 lines and then the data starts after three *.
Example median data_date_time
Comments and machine specifications:
... (for 30-60 lines)
Data: x, y, z, etc.
***
-8.710498,-0.039902,0.021362,-0.028009,-0.006365
-8.689081,-0.022736,0.006943,-0.027939,-0.006338
-8.667665,-0.014191,0.031357,-0.027870,-0.006311
-8.646248,-0.018768,0.033569,-0.027800,-0.006283
-8.624832,-0.029907,0.025787,-0.027731,-0.006256
-8.603415,-0.037689,0.003281,-0.027661,-0.006228
-8.581999,-0.048065,-0.009613,-0.027591,-0.006200
... (for 1024 points).
I've read some comparable questions in the forums and tried to format the answers to my problem but I've had no luck. What I do understand is that I have to read the file from the beginning, skip all 30-60 lines before *s and read the data after but I don't know how.

Best Answer

opt = {'Delimiter',','};
fmt = repmat('%f',1,5);
C = {};
fid = fopen('test.txt','rt');
while ~feof(fid)
str = fgetl(fid);
if strncmp('***',str,3)
C{end+1} = textscan(fid,fmt,opt{:});
end
end
fclose(fid);
Your data is in C.