MATLAB: Convert Table to Matrix

MATLABmatrixtable

Hey everyone,
I know this has been discussed in the community quite often, but after going through the answers for four hours know, I still havent found a way to handle my problem, so i would be very thankful if someone of you guys could help me out! I have data which looks like this and which is separated by two spaces:
if i try to import it with the following code (I've already tried it with readmatrix, it doesn't work):
clear all
clear
filename=uigetfile('*.dat');
A=readtable(filename,'Delimiter','\t');
I know get a table with the format 370×1, which is useless to me, because I am trying to do a surf plot with all the numeric data on the right. The Table I get looks like this:
I would be really glad If somebody could help me out, because right now, I am prepreparing the data in excel, and the plot and everything else works perfectly fine, but I would like to it directly with the dat file!
Thank you in advance and best regards from germany, Lukas

Best Answer

My suggestion would be to use the Import Tool. This will allow you to interactively create your import. There is an option to generate an import script or function as well.
Along the way, you get to inspect your data. In particular, you will notice that you have an inconsistent number of columns of data. This is going to possibly complicate creating a surface from the data, though not necessarily. The shorter rows will be padded with NaN.
I was able to successfully import the data using both the Import Tool and fixedWidthImportOptions.
numVars = 48;
opts = fixedWidthImportOptions("NumVariables",numVars,...
"DataLines",2);
opts = setvartype(opts,1,"datetime");
opts = setvartype(opts,2:numVars,"double");
opts = setvaropts(opts,1,"InputFormat","dd.MM.yyyy HH:mm:ss");
opts.VariableWidths = [19 2 4 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7];
data = readtable("tex_file.dat",opts)
From the the table, you could create a surf using the following code. For additional details on accessing data in a table, see this page.
surf(data{:,2:end})