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

124 次查看(过去 30 天)
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 个评论
Marco Riani
Marco Riani 2024-4-16
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

请先登录,再进行评论。

回答(1 个)

Ameer Hamza
Ameer Hamza 2020-5-8
编辑:Ameer Hamza 2020-5-8
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 个评论
Stephen23
Stephen23 2020-5-9
"...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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Cell Arrays 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by