Azzera filtri
Azzera filtri

Operator '-' is not supported for operands of type 'table'.

124 visualizzazioni (ultimi 30 giorni)
X = readtable('FinalProj_TVdata.csv');
Y = readtable('FinalProj_Pdata.csv');
%Convert from Fahrenheit to Kelvin
TempK = ((X(:,1)-32)*5/9)+273.15;
%Determine Volume
V = X(:,2)*0.028;
So I have been attempting to find the temperature and volume using this code, but I am having troubles.
  1 Commento
Marco Riani
Marco Riani il 16 Apr 2024
This is just to notice that starting from 2023A the syntax below is valid and there is now no need to use {} or table2array (array2table)
X = readtable('FinalProj_TVdata.csv','VariableNamingRule','preserve');
TempK = ((X(:,1)-32).*(5/9))+273.15
TempK = 300x1 table
T (F) ______ 290.46 291.37 288.72 296.71 287.78 294.93 294.34 294.04 295.36 298.93 293.98 292.26 295.4 289.15 294.21 296.71

Accedi per commentare.

Risposte (1)

Ameer Hamza
Ameer Hamza il 8 Mag 2020
Modificato: Ameer Hamza il 8 Mag 2020
table elements need to be accessed using brace indexing. Try this
X = readtable('FinalProj_TVdata.csv');
TempK = ((X{:,1}-32)*5/9)+273.15;
%Determine Volume
V = X{:,2}*0.028;
Alternative
You can convert the table to array and then use normal indexing
X = table2array(readtable('FinalProj_TVdata.csv'));
TempK = ((X(:,1)-32)*5/9)+273.15;
%Determine Volume
V = X(:,2)*0.028;
  3 Commenti
Ameer Hamza
Ameer Hamza il 8 Mag 2020
Modificato: Ameer Hamza il 8 Mag 2020
I am glad to be of help.
Stephen23
Stephen23 il 9 Mag 2020
"...I didn't know table elements needed braces."
They don't need them, it depends entirely on what you want to achieve. Like all MATLAB indexing, indexing using parentheses always returns an array of exactly the same class, so if you use parentheses then you will get a table, whereas curly braces refers to the contents of the container array. So for a table:
  • () returns another table
  • {} returns the contents of the table.
This is explained in the MATLAB documentation:
The same principle applies to other container arrays too, e.g. cell arrays, string arrays.

Accedi per commentare.

Categorie

Scopri di più su Cell Arrays in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by