필터 지우기
필터 지우기

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

조회 수: 124 (최근 30일)
Ryan Scott
Ryan Scott 2020년 5월 8일
댓글: Marco Riani 2024년 4월 16일
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
Ameer Hamza
Ameer Hamza 2020년 5월 8일
편집: Ameer Hamza 2020년 5월 8일
I am glad to be of help.
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