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

249 views (last 30 days)
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 Comment
Marco Riani
Marco Riani on 16 Apr 2024 at 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

Sign in to comment.

Answers (1)

Ameer Hamza
Ameer Hamza on 8 May 2020
Edited: Ameer Hamza on 8 May 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 Comments
Stephen23
Stephen23 on 9 May 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.

Sign in to comment.

Categories

Find more on Cell Arrays in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!