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 Comments

It is because Vc is table......it is not double as you are expecting.
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)
There might by a typo in "idGase" - do you really need the trailing "e"?
Sorry for the late reply, thanks for all the help. I'm new to matlab so what does that script of functions actually do?

Sign in to comment.

Answers (3)

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.

Categories

Find more on Get Started with MATLAB in Help Center and File Exchange

Asked:

on 9 Nov 2018

Answered:

on 15 Nov 2018

Community Treasure Hunt

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

Start Hunting!