MATLAB: Loading every n-th column of a csv with varying formats in row using textscan

excelimporting excel datatextscan

Hi, i am trying to load a csv file with semicolon (;) delimiter.
Example:
150501;190722;ms_since_start=;30001276;temp=;31.97;IT=;147753;spec num=;1000;(here i have 512 floating number repetitions and ';;' to indicate the end of line)
this pattern repeats for 1000 rows.
I have been trying to use textscan but only get empty cells with the following code
formatSpec = ['%s%s%*s%*s%*s%*s%*s%*s%*s%*s%*s' repmat('%f', [1,512]) '%*[^;;]']
M = textscan(dirtmp, formatSpec, 'Delimiter', ';')
The goal is to get the first 2 columns, skip 9, get the remaining 512 columns and repeat this for 1000 rows.
Any help is highly appreciated

Best Answer

You may need to change the last part of your ‘formatSpec’ line deleting the '%*[^;;]' and including 'MultipleDelimsAsOne',1 and 'EndOfLine','\r\n' or perhaps something else if you have a different end-of-line indicator.
Also consider this as the first part of your ‘formatSpec’:
'%f;%f;ms_since_start=;%f;temp=;%f;IT=;%f;spec num=;%f'
No promises these will solve your problems, but I would experiment with those and other options until I got it working.