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

228 visualizaciones (últimos 30 días)
Ryan Scott
Ryan Scott el 8 de Mayo de 2020
Comentada: Marco Riani el 16 de Abr. de 2024 a las 8:37
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 comentario
Marco Riani
Marco Riani el 16 de Abr. de 2024 a las 8:37
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

Iniciar sesión para comentar.

Respuestas (1)

Ameer Hamza
Ameer Hamza el 8 de Mayo de 2020
Editada: Ameer Hamza el 8 de Mayo de 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 comentarios
Ameer Hamza
Ameer Hamza el 8 de Mayo de 2020
Editada: Ameer Hamza el 8 de Mayo de 2020
I am glad to be of help.
Stephen23
Stephen23 el 9 de Mayo de 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.

Iniciar sesión para comentar.

Categorías

Más información sobre Cell Arrays en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by