Print variable text with a numerical variable.

2 visualizaciones (últimos 30 días)
Victoria Viridiana Cabrera Díaz
Victoria Viridiana Cabrera Díaz el 18 de Jun. de 2020
Hi
I'm working thermodynamics, so there's a bunch of R constants that I can use and they all have different units, the user can choose this constant
I want the user to give me values for PVTn and calculate the one that is missing if so. Then I print it in a message box, but I want the text to change according to the R constant chosen so it can say "The temperature is: x K" or "The temperature is x: °C"
I have 4 states, 3 variables for each state (P1, V1, T1, P2, V2...), so I don't want to do a lot of "if", I was trying to create a new variable and print it in the message box, but it won't let me do that
Thanks in advance for your help
erres={'8.314','0.08314','83.14','0.00008314','0.08206','1.98','1.987','10.73'};
[menu1] = listdlg('PromptString',...
{'Selecciona un valor de R para realizar los cálculos'},...
'SelectionMode','single','ListString',erres,'ListSize',...
[300,100],'name','Constante R');
if menu1==1
R=8.314;UP=({'Pa'});UV='m^3';UT='K';%This is the text that I'm trying to print after the variable
end %I didn't include the other options of the menu, but there are 8 options
%The display looks like this
if P1==0
P1 = (n*R*T1)/V1;
uiwait(msgbox(sprintf('El valor de la presión 1 es: %2.3g %2.3',P1,UP),'P1'));
end %Again, I didn't include the other options, there are 12 in total, that's why I don't want to use if for each R

Respuestas (1)

Mara
Mara el 18 de Jun. de 2020
What about you make three more vectors, UP, UV and UT...
UP = ["Pa", MPa" , or whatsoever] that have the same length as erres.
Then you use your variable menu 1 to index into these vectors and display it in the messagebox.
You can also index with it into erres:
erres{menu1};
or if you want to convert it into a double that you can calculate with:
str2double(erres{menu1} );
Note: you have to convert them all into strings, which in case of your doubles you can do with num2str();
if P1==0
P1 = (n*R*T1)/V1;
uiwait(msgbox(strcat('El valor de la presión 1 es:',num2str(P1),num2str(UP(menu1))),'P1'));
end

Categorías

Más información sobre Startup and Shutdown en Help Center y File Exchange.

Productos


Versión

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by