MATLAB: How to use the excel import functionality in Matlab to import a table but to have the individual pices of data in the table rows to not be imported as 1×1 tables as well

1x1 tablesdata importimporting excel datatable operations

When I import excel spreadsheets as tables it imports each piece of data as a 1×1 table which creates problems when I want to operate on those variables. For example, I cannot create new variables that are the squares and cubes of existing variables when each piece of data is a 1×1 table. What is the best way to handle this? Can I have the excel import function import the excel sheet as a table but have it cast each piece of data as a double?

Best Answer

I imagine what's happening is this: you are importing a spreadsheet using readtable, and you get a table.
>> t = readtable('myfile.xlsx')
t =
5×3 table
Var1 Var2 Var3
_______ _______ _______
0.81472 0.09754 0.15761
0.90579 0.2785 0.97059
0.12699 0.54688 0.95717
0.91338 0.95751 0.48538
0.63236 0.96489 0.80028
Then you select one element of that table:
>> t(1,1)
ans =
table
Var1
_______
0.81472
And so you are thinking that the import has created a bunch of little 1x1 tables.
But that isn't it at all. The short answer is that you likely need to use some other form of subscripting, probably something like
>> t.Var1(1)
ans =
0.81472
The longer answer is that you likely do not want to select one value at a time. Doing vectorized calculations is usually the better way. No way to tell without more context.
There's a whole doc section of how to use subscripting to access data in a table.