MATLAB: How to extract data from .mat file that contains table

cell arraysMATLABmatrixtable

Hi everyone,
I would like extract data from table on the .mat file. I tried to convert the 'struct' into 'cell' obtaining a cell array 1×1 and then I tried to convert 'cell' into numeric array but cell2mat doesn't support cell array. The goal is to obtaine a matrix of dimension 30932×5. Are there someone that can help me? Thanks.
fileName = 'D:\Valerio\data\data_models\ACCESS1_0.mat';
loadfile = load(fileName);
table = struct2cell(loadfile);
data_matrix = cell2mat(table);
data_matrix = cell2mat(table)
Error using cell2mat (line 52)
CELL2MAT does not support cell arrays containing cell arrays or objects.

Best Answer

Hi,
Here is my answer for your question. Please read my comments near each line.
table_loaded = load('C:\Users\hingec\Downloads\ACCESS1_0.mat'); % loaded structure
your_actual_table = table_loaded.table_def; % this struct already have a table_def field and that field contains a table.
your_timetable = table2timetable(table_loaded.table_def); % You can convert it to timetable.
%% Once you get your table you can reach each column with dot notation like below:
date_array = your_timetable.YYMMDD; % type is datetime
H_array = your_timetable.HH; % type is int32
Hs_tot_array = your_timetable.Hs_tot; % type is single


Tm_tot_array = your_timetable.Tm_tot; % type is single
Dm_tot_array = your_timetable.Dm_tot; % type is single
% Now manipulate them and make some convert operations because you can't
% concatanate int32, single and datetime into a double matrix.
%% For example:
H_array_converted = double(H_array); % now it is type double.
% if you don't do conversion, you can't even make mathematical operations. For example try to sum 2nd elements of arrays:
H_array(2) + Hs_tot_array(2) % this will give error. Because you can't sum int32 and single.