MATLAB: How to import data from excel file as structure into Matlab

importing excel datatable to structure

Hello, I have a relatively straight forward problem:
I have an excel sheet with two columns. The first column contains names and the second column contains numeric values. How can I import this file as a struct, so that I can access the values simply by their name?

Best Answer

T = readtable(TheFileName);
TC = table2cell(T);
TS = cell2struct(TC(:,2), TC(:,1), 1);
TS will now be a cell with field names according to the first column of the file and numeric value according to the second column of the file.
Related Question