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?
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
T4H14
le 23 Avr 2018
Modifié(e) : Rena Berman
le 16 Juil 2024 à 16:50
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?
0 commentaires
Réponse acceptée
Peter Perkins
le 24 Avr 2018
Modifié(e) : Rena Berman
le 16 Juil 2024 à 16:50
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.
0 commentaires
Plus de réponses (1)
Ameer Hamza
le 23 Avr 2018
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.
0 commentaires
Voir également
Catégories
En savoir plus sur Spreadsheets dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!