Graphical output of subscripts in one main script

1 view (last 30 days)
I have four subscripts called Fig_4, Fig_5, Fig_6, Fig_7 basically similar to each other. Each of these has a graphic output and I need to call only this graphic output (preferably in a subplot) within a main script. I tried with the run command but it only returns the last line of code. Semicolons seem to make no difference. Below I leave you the script Fig_4 if necessary:
clc, clear, close all
%% Dati
T=[150 170]; % Temperatura operativa sperimentale [°C]
T=T+273.15; % Temperatura operativa sperimentale [K]
Trif=170+273.15; % Temperatura di riferimento [K]
R=8.314; % Costante dei gas [J/molK]
Vr=5e-5; % Volume di reazione [m3]
texp=[0 0.5 1 2 4]; % Tempi sperimentali dei prelievi [h]
tspan=linspace(0,4,1000);
% Composizione iniziale del sistema [mol] e [mol/m3]
nA0=0.1; % A=AA=Acido Acrilico [mol]
cA0=nA0/Vr; % Concentrazione A [mol/m3]
nB0=1.2*nA0; % B=2EH=2-etilesanolo [mol]
cB0=nB0/Vr; % Concentrazione B [mol/m3]
nC0=0; % C=2EHA [mol]
cC0=nC0/Vr; % Concentrazione C [mol/m3]
nI=0.01*nA0; % I=inibitore PTZ [mol]
cI=nI/Vr; % Concentrazione inibitore [mol/m3]
ncat=0.01*nA0; % cat=catalizzatore [mol]
ccat=ncat/Vr; % Concentrazione catalizzatore [mol/m3]
c0=[cA0 cB0 cC0 cI ccat];
% Energie di attivazione [J/mol]
Ea1=85.1*1000;
Ea2=130*1000;
Ea3=66.5*1000;
Ea4IN=0*1000; % In presenza di inibitore PTZ
Ea=[Ea1 Ea2 Ea3 Ea4IN];
% Costanti cinetiche di riferimento [m3/(mol2 h)]
krif1IN=2.12e-5; % In presenza di inibitore PTZ
krif2=3.4e-5;
krif3=8.1e-6;
krif4IN=0; % In presenza di inibitore PTZ
krif=[krif1IN krif2 krif3 krif4IN];
% Costante cinetica della reazione secondaria di inibizione ad opera di PTZ
KI=842.5;
% Figura 4 - PTZ as inhibitor: cat 1%, PTZ 1%; MR=1.2
x4exp150=[45.84013 73.93148 84.01305 93.89886 98.00979];
x4exp170=[75.88907 93.01794 95.95432 98.98858 99.96737];
y4exp150=[8.254490 54.15987 70.79935 87.14519 91.94127];
y4exp170=[44.37194 75.59543 90.47308 88.80914 85.57912];
%% Script
for j=1:length(T)
Tj=T(j);
fn=@(t,c4)bilancio_4(t,c4,Ea,R,Tj,Trif,krif,ccat,KI,cI);
[t,c4]=ode45(fn,tspan,c0);
xA4(:,j)=((cA0-c4(:,j))/cA0)*100;
y4(:,j)=c4(:,j)/cA0;
end
%% Output
plot(tspan,xA4(:,1),'k-', ...
tspan,xA4(:,2),'k-')
hold on
plot(tspan,y4(:,1),'r-', ...
tspan,y4(:,2),'r-')
hold on
plot(texp,x4exp150,'^', ...
texp,x4exp170,'s', ...
'MarkerEdgeColor','black',...
'MarkerFaceColor','black')
hold on
plot(texp,y4exp150,'rs', ...
texp,y4exp170,'r^')
hold off
xlabel('Time, \ith\rm')
ylabel('Conversion, %')
colororder('k')
yyaxis right
yyaxis('right')
ylabel('Yield, %')
ylim([0 100])
% legend('150 °C Conversion','170 °C Conversion','150 °C Yield','170 °C Yield','Location','southeast')
grid on
grid minor
%% Bilancio
function dcdt = bilancio_4(t,c4,Ea,R,Tj,Trif,krif,ccat,KI,cI)
cA=c4(1);
cB=c4(2);
cC=c4(3);
k(1)=krif(1)*exp((-Ea(1)/R)*((1/Tj)-(1/Trif)));
k(2)=krif(2)*exp((-Ea(2)/R)*((1/Tj)-(1/Trif)));
k(3)=krif(3)*exp((-Ea(3)/R)*((1/Tj)-(1/Trif)));
k(4)=krif(4)*exp((-Ea(4)/R)*((1/Tj)-(1/Trif)));
r1=k(1)*ccat*cA*cB;
r2=(k(2)*ccat*(cA^2))/((1+(KI*cI))^2);
r3=(k(3)*ccat*cB)/(1+(KI*cI));
r4=k(4)*cI;
dcdt(1)=-r1-(2*r2)-r3;
dcdt(2)=-r1-r3;
dcdt(3)=r1;
dcdt(4)=-r4;
dcdt(5)=ccat;
dcdt=dcdt';
end
For the chemists out there: I know that the output is totally a mess but is a matter of numbers. Need to discuss with professor.

Answers (1)

chicken vector
chicken vector on 25 Apr 2023
Edited: chicken vector on 25 Apr 2023
Your code is fine but you need to delete the first line:
clc, clear, close all
I did it and saved your script naming it fig_4.m and run this:
figure;
tiledlayout(2,2);
for j = 1 : 4
nexttile;
fig_4;
end
Result:
  3 Comments
Domenico Guarino
Domenico Guarino on 25 Apr 2023
Done this way and it worked. Thank you.
tiledlayout(2,2);
nexttile
Fig_4;
title('Figura 4')
nexttile;
Fig_5;
title('Figura 5')
nexttile;
Fig_6;
title('Figura 6')
nexttile;
Fig_7;
title('Figura 7')

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!