Unfortunately, with these kinds of data, “readtable” function would not be able to satisfy your needs as it can’t deal with variable number of columns. A potential workaround to this issue, which will import a table into MATLAB from your DAT file, is to use the import data tool available for MATLAB R2016a. The interface is automatically invoked when you open the DAT file in MATLAB, or you can click on the “Import Data” button under the “VARIABLE” section of the “HOME” tab of the MATLAB window.
Steps to import a table into MATLAB from DAT file is as follows:
1. Navigate to the folder containing your DAT file in MATLAB.
2. Type the following command in the Command Window:
>>open my_data.dat
3. The MATLAB import data interface will open. There are five sections in the ribbon under the “Import” tab. Under the “DELIMITERS” section, by default, data is read assuming the tab delimiter for columns. You can adjust the delimiters accordingly here.
4. Press CTRL-A to select the entire spreadsheet for import, or select portions of the spreadsheet to import as you desire.
5. Under the “IMPORTED DATA” section, select “Table” to import the spreadsheet into MATLAB as a table. You may also import the selection as a set of column vectors, numeric matrix, or cell array by choosing the appropriate option under this section.
6. Under the “UNIMPORTABLE CELLS” section, you may choose to have MATLAB read empty fields as NaN (by default), or other placeholders as you desire.
7. Under each column heading, you may manually change the format of each column to have MATLAB import the column as “text”, “number”, or “date”, as needed.
8. Finally, if you wish to import the data into MATLAB now, you may click on the green checkmark button under the “IMPORT” section of the panel. The interface will inform you the variable name of the table created. In addition, you may also automate this process by generating a script or a function for this import operation. Simply click on the drop down menu beneath the green checkmark, and select generate script, or generate function, as desired.