I´m going to submit a formal answer to my own question just in case someone else runs into this problem.
The problem is twofold here, getting the variable names and getting the data out.
Lets start with the names.
What I had to do at first was run detectimportoptions to get the object "opts" containing a lot of relevant information about the file
Then use fopen and fgetl to assign the fragmented variable names to two different variables, called line1 and line2.
opts = detectImportOptions('file');
fid = fopen('file');
%Go to line 5 (first line of variable names)
g = 1;
for f = 1:5
line1 = fgetl(fid);
g = g+1;
f = g;
%Go to line 6 (second line of variable names)
line2 = fgetl(fid);
fid = fclose(fid)
Now that the broken variable names have been detected and saved, it´s time to join them into one string. This being a CSV file delimited by a variable delimiter it is important to remove the delimiters from the end of the strings or when we will come to split them, the extra delmiters will cause issues.
This is where the opts object becomes useful as detectimportoptions will find the delimiter for you
Once we have defined the delimiter string we run a strfind to find the first delimiter in the series of delimiters that are at the end of the line. strfind returns the index of the 1st delimiter that matches the pattern. we remove 1 from that index to make sure we delete it.
% find the semicolons at the end of each line and remove them
delimiter = opts.Delimiter;
delimiters = [delimiter delimiter delimiter delimiter delimiter delimiter delimiter];
delimiters = strjoin(string(delimiters));
delimiters = strrep(delimiters, ' ', '');
linefind = strfind(line1,semicolons);
line1 = line1(1:(linefind(1)-1));
We do this for both lines.
linefind = strfind(line2,delimiters);
line2 = line2(1:linefind(1));
We then combine the strings of line1 and line2 then use strsplit to divide each name into cells and ~isempty to remove the blanks. We are left with an array of variable names.
%Combine strings of the two lines to what the correct line should be
newline = strcat(line1,line2);
%Generate header names
headernames = strsplit(newline,delimiter);
headernames = headernames(~cellfun('isempty',headernames));
Now for the data.
We can use the opts object to our advantage here by editing select properties where possible. For instance it was not possible (i dont know why) to actually set in opts what the variable names are by changing the content of opts.variablenames, but I had success in specifying the start of the datalines by changing opts.datalines. This will cause readtable to ignore every line above this specified line, while maintaining the import properties of each column. opts. datalines has 2 values for start and end of data. We only need to change one.
opts.DataLines(1) = 7;
F = readtable('file',opts);
From here we get a table of data that (hopefully) is the same length as headernames.
All we need to do from here is create a loop the same length as headernames to change each table variable name to the corresponding headername. Since we maintained the order of the names when we split the string, this is a simple 1 to 1 replacement.
for i = length(headernames)
F.Properties.VariableNames(i) = headernames(i);