What does Undefined operator '*' for input arguments of type 'table' mean
古いコメントを表示
I have the following code here
A= readtable('Exceltable.xlsx')
idGas= input('enter name of a gas','s')
switch idGas
case "He"
idGas=1;
case "Ne"
idGas=2;
case "H2"
idGas=3
case "CO2"
idGas=4
case "Ar"
idGase=5
case "CH4"
idGas=6
case "H2O"
idGas=7
end
a=A(idGas,2);
b=A(idGas,3);
Pc=A(idGas,4);
Tc=A(idGas,5);
Vc=A(idGas,6);
R=8.3145
%letting our ranges for the variables v and t
v=(0.7*Vc):(0.001*Vc):(20*Vc);
%Then we plot an equation using the values we just obtained
hold on
for t=tc:(0.1*tc):(1.5*tc)
P=((R*t)./(v-b))-(a./(v^2));
plot(P/Pc,((P.*v)./(R*t)),2)
grid on
xlabel('P/Pc')
ylabel('Pv/Rt')
legend('Tc','1.1Tc','1.2Tc','1.3Tc','1.4Tc','1.5Tc')
end
hold off
And when I run the code every part of the function is running except for the equation.
v=(0.7*Vc):(0.001*Vc):(20*Vc)
It then says that there is an
Undefined operator '*' for input arguments of type 'table'.
I have no idea what that means and how I can fix it. Any guesses?
4 件のコメント
KSSV
2018 年 11 月 9 日
It is because Vc is table......it is not double as you are expecting.
Stephen23
2018 年 11 月 9 日
Note that you can replace the entire switch statement with this:
S = input('enter name of a gas','s')
C = {'He','Ne','H2','CO2','Ar','CH4','H2O'};
[~,idGas] = ismember(S,C)
Jan
2018 年 11 月 9 日
There might by a typo in "idGase" - do you really need the trailing "e"?
William Anderson
2018 年 11 月 15 日
編集済み: William Anderson
2018 年 11 月 15 日
回答 (3 件)
KSSV
2018 年 11 月 9 日
Use
Vc=A{idGas,6}
wherever possible,
madhan ravi
2018 年 11 月 9 日
v=(0.7*A.Vc):(0.001*A.Vc):(20*A.Vc)
Peter Perkins
2018 年 11 月 15 日
Tables are containers. Even if you have all numbers in a table, it's still a container around the numbers. The reason is that tables are primarily designed to contain data of different types.
This is usually not an issue, you just have to be aware of the difference bet6ween the contianer and the stuff in the container. In your case, these lines
a=A(idGas,2);
b=A(idGas,3);
Pc=A(idGas,4);
Tc=A(idGas,5);
Vc=A(idGas,6);
are, I guess, supposed to pull out scalar values for a particular gas. But because you are using perentheses, each of those values is a 1x1 table, and because tables are containers, they don't support multiplication even if the only thing in them is numeric. The short answer is to replace those parens with curly braces. See the doc for tabloes to read all about that.
A longer answer is that you ought to be creating your excel sheet with row and column heading, and have read those in as row and variable names, and then your code won't need to convert idGas into a number (so no switch statement at all), and you can use Vc instead of 6. In fact, you'd just say
Vc = A.Vc(idGas)
etc.
カテゴリ
ヘルプ センター および File Exchange で MATLAB についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!