How can I 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 1x1 tables as well?

1 回表示 (過去 30 日間)
When I import excel spreadsheets as tables it imports each piece of data as a 1x1 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 1x1 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?

採用された回答

Peter Perkins
Peter Perkins 2018 年 4 月 24 日
編集済み: Rena Berman 2024 年 7 月 16 日
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.

その他の回答 (1 件)

Ameer Hamza
Ameer Hamza 2018 年 4 月 23 日
Although you can change the entries in a MATLAB table. But for your case, you can convert your table into a double matrix as
myMatrix = cell2mat(myTable{:});
Then you can do the required calculations.

カテゴリ

Help Center および File ExchangeSpreadsheets についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by