MATLAB: Can I name part of a variable after a string

horrible bad ideaMATLABnamerenamestringvariablevariables

Hello! I'm a new user, so sorry if I'm doing a stupid question, but here is my problem: Instead of having this program:
CO2_Tc = 304.12;
H2O_Tc = 647.14;
Name = input('Input name: ','s');
switch Name
case 'CO2'
T = input('Input temperature: ');
Tc = CO2_Tc;
Tr = T/Tc
case 'H2O'
T = input('Input temperature: ');
Tc = H2O_Tc;
Tr = T/Tc
otherwise
disp('Invalid name')
end
Could I have something like:
CO2_Tc = 304.12;
H2O_Tc = 647.14;
Name = input('Input name: ','s');
T = input('Input temperature: ');
Tc = (Name)_Tc; %Here, Name would be replaced by the user's input, like CO2 or H2O
Tr = T/Tc
Is it possible?

Best Answer

It is possible, but firmly not recommended
What I would recommend in your case is to have something like
Tc_vals = struct('CO2', CO2_Tc, 'H2O', H2O_Tc);
and then you could use
Tc = Tc_vals.(Name);