MATLAB: Reading .csv Files with different number of Columns

csvMATLABreadtabletextscan

Hi There
I'm trying to import data from various .csv Files with different numbers of columns. I want to write a function that can import data from .csv-Files without knowing the number of columns beforehand. All columns must be read and imported.
Example of data.csv:
"datetime";"SensorId_3";"SensorId_4";"SensorId_13"
"2017-06-01 00:00:05";"9999";"4444";"5555"
"2017-06-01 00:00:15";"9999";"4444";"5555"
"2017-06-01 00:00:25";"9999";"4444";"5555"
"2017-06-01 00:00:35";"9999";"4444";"5555"
The .csv are always written in this style but the Number of Columns can change. So far I've tried the Matlab Import Data Function to write a function for Importing data but it doesn't work for other Files with different number of columns. Also I've done some experimenting with "textscan" and "readtable", but didn't get to a solution.
With "readtable" i cannot omit the quotation marks when reading (yes, I've tried formatSpec).
With textscan, i can get my data into one Vector (More or less I've copied the generated code from the Matlab Import Function):
datavector =
2017-06-01 00:00:05
9999
4444
5555
2017-06-01 00:00:15
9999
4444
Thanks for any advice!

Best Answer

In R2017b and R2018a, readtable runction could read your data. If the number of columns changes, how about changing data-type after reading CSV data, like:
T = readtable('data.csv');
T.datetime = datetime(T.datetime);