Need to read a huge text file full of weirdly formatted data. The format goes like this:
//Header with Title Info
//Header with Test1 Info
//More Test1 Info
0,-156.875956035285
1.953125,-4.82866496038806
3.90625,-8.93502887648155
5.859375,-9.76964479822559
7.8125,-14.9767168331976
9.765625,-16.9949034672061
11.71875,-19.2709033739316
13.671875,-18.9948581866681
//Header with Test2 Info
//More Test2 Info
0,-156.875956035285
1.953125,-4.82866496038806
3.90625,-8.93502887648155
5.859375,-9.76964479822559
7.8125,-14.9767168331976
9.765625,-16.9949034672061
11.71875,-19.2709033739316
13.671875,-18.9948581866681
//Header with Test3 Info
//More Test3 Info
0,-156.875956035285
1.953125,-4.82866496038806
3.90625,-8.93502887648155
5.859375,-9.76964479822559
7.8125,-14.9767168331976
9.765625,-16.9949034672061
11.71875,-19.2709033739316
13.671875,-18.9948581866681
// End of Data
That's the gist of it, except there are about 25,000 entries for under each header instead of 8. I'm running 25 tests which need to be averaged together into one set of data.
Essentially, I want to parse through the data in this sequence:
- Skip first line
- Recognize empty line, go to next
- Check for "End of Data"
- If not the end, skip current line and the next line
- Create new array for current set of test data
- Read data until empty line is reached, then go back to step 2
Then, I want to average all of these sets together in the most efficient way.
I'm having trouble reading the data. I know I could use csvread, or a more general function to read the delimited values, but I'm kind of stuck with figuring out an elegant and concise way to do everything.
I started with this:
function [ data ] = graph( input_args )
%Plot data
myData = fopen('mRoom_fSweep_25points_center.txt');
data = textscan(myData,'%s');
fclose(myData);
length(data)
end
And I figured I could just find the length of this array of strings, and work out a for-loop for the whole list of operations, but I couldn't get past this point: the output kept giving me this:
ans =
{772321x1 cell}
Which I can't use. When I try and store this in a variable, it gives a value of 1. Is there something weird with cell arrays I'm missing here?