%% ===================== Monte Carlo simulation for parameter uncertainty ===================== % SensTest aims to assess how values of Young's modulus E, magma viscosity (mu_m), and the vertical extent of the melting zone H affect residual pressure calculations in the physical volcanological model. % Four Monte Carlo experiments are implemented: three single-variable tests for Young's modulus, magma temperature, and melting zone vertical extent respectively, with other parameters fixed; the fourth experiment varies all three variables concurrently. % Users simply enter the model's numeric identifier upon prompt to generate outputs for 10,000 Monte Carlo trials. % Full simulation details are given in Yang et al. (2026). % 1 - Random Young's Modulus (E only) % 2 - Random Magma Temperature (Tmag only) % 3 - Random Melt Zone Thickness (H only) % 4 - All Three Parameters Random clear; clc; close all; rng(1); % Fix random seed for fully reproducible results %% ===================== Volcanic Physics Model ===================== function [P_r_MPa, Po_MPa, dP_crit_MPa, Pe_MPa] = VolcPhyModel(E_GPa, etam, H_km, rho_crust, D_km, dTwr_dx) % Physical constants (The fixed parameter values can be found in Table S2.) g = 3.72; % Martian gravitational acceleration, m/s^2 rho_m = 3000; % Density of magmatic crystals, kg/m^3 sigma_d_MPa = 0.11; % Differential stress, MPa sigma_d = sigma_d_MPa * 1e6; kappa = 3e-7; % Thermal diffusivity of magma, m^2/s c = 1600; % Specific heat capacity, J/(kg·K) L = 414e3; % Latent heat of crystallization, J/kg % Mantle density stratification if D_km < 44.2 rho_M = 3347; elseif D_km <= 80 rho_M = 3462; else rho_M = 3500; end E = E_GPa * 1e9; H = H_km * 1000; D = D_km * 1000; %% Governing equations % Eq. (1): Buoyancy excess pressure Pe = g .* (rho_M - rho_m) .* H; % Eq. (2): Total reservoir overpressure Po = Pe + (rho_crust - rho_m) .* g .* D + sigma_d; % Eq. (3): Critical overpressure for dike initiation term1 = (kappa .* etam ./ pi).^(1/2); term2 = (c .* dTwr_dx ./ L) .* E.^2; dP_crit = 3.5 .* ( term1 .* term2 ).^(2/5); % Eq. (4): Residual pressure after dike formation P_r = Po - dP_crit; Pe_MPa = Pe / 1e6; Po_MPa = Po / 1e6; dP_crit_MPa = dP_crit / 1e6; P_r_MPa = P_r / 1e6; end %% Model Selection Menu fprintf('===== Select Monte Carlo Simulation Model =====\n'); fprintf('1 - Random Young''s Modulus (E only)\n'); fprintf('2 - Random Magma Temperature (Tmag only)\n'); fprintf('3 - Random Melt Zone Thickness (H only)\n'); fprintf('4 - All Three Parameters Random\n'); model_choice = input('Please enter the model number (1-4): '); switch model_choice case 1 % Case 1: Random Young's Modulus (E only) fprintf('\n===== Running: Random Young''s Modulus (E only) =====\n'); % Parameter configuration N_trials = 10000; %10000 MC trials per group rho_list = [2600,2700,2800,2900,3000]; % Columns: crustal density D_list = [10,30,50,70,90]; % Rows: crustal thickness % Viscosity parameters from Table S2, calculate μ_m using formula S3 mu0 = 151.4; % Directly given in Table S2, viscosity of pure magma, Pa·s phi = 0.55; % Crystal volume fraction phi0 = 0.64; % Crystal constant C = 3; % Crystal constant etam_fixed = mu0 * ((1-phi)/(1-phi/phi0))^( (C*phi0)/(1-phi0) ); fprintf('Calculated crystal-bearing magma viscosity etam = %.4e Pa·s\n',etam_fixed); H_fixed = (7.5 + 15.8)/2; % Fixed melt zone thickness, midpoint of 7.5~15.8 E_min = 10; E_max =100; % Sole random variable: E(GPa) % dTwr/dx (℃/km) corresponding to ρ from literature, converted to K/m % rho: 2600 2700 2800 2900 3000 % dT(℃/km): 16 15.4 14.9 14.4 13.9 dTwr_Cperkm_list = [16, 15.4, 14.9, 14.4, 13.9]; dTwr_Kperm_list = dTwr_Cperkm_list / 1000; % ℃/km → K/m n_rho = length(rho_list); n_D = length(D_list); Pr_all = zeros(n_D, n_rho, N_trials); % D(rows),rho(columns),samples %% Monte Carlo simulations for iD = 1:n_D D = D_list(iD); for irho =1:n_rho rho = rho_list(irho); % Fetch temperature gradient corresponding to current rho dTwr_dx = dTwr_Kperm_list(irho); fprintf('Calculating D=%d km, rho=%d kg/m3, dTwr/dx=%.4f K/m\n',D,rho,dTwr_dx); for it = 1:N_trials E_samp = unifrnd(E_min,E_max); [Pr,~,~,~] = VolcPhyModel(E_samp, etam_fixed, H_fixed, rho, D, dTwr_dx); Pr_all(iD,irho,it) = Pr; end end end %% Plot 5×5 subplot array fig = figure('Color','w','Position',[100,100,1200,1200]); t = tiledlayout(n_D,n_rho,'TileSpacing','compact','Padding','compact'); title(t,'Crustal density (kg m^{-3})','FontSize',16,'FontName','Arial','FontWeight', 'bold'); ylabel(t,'Crustal thickness (km)','FontSize',16,'FontName','Arial','FontWeight', 'bold'); for iD = 1:n_D D_val = D_list(iD); for irho =1:n_rho rho_val = rho_list(irho); ax = nexttile; Pr_sample = squeeze(Pr_all(iD,irho,:)); meanPr = mean(Pr_sample); stdPr = std(Pr_sample); h = histogram(ax,Pr_sample,20); h.FaceColor = [0.98,0.85,0.2]; h.EdgeColor = [0.2,0.2,0.2]; hold(ax,'on'); pd = fitdist(Pr_sample,'Normal'); x_fit = linspace(min(Pr_sample),max(Pr_sample),200); y_fit = pdf(pd,x_fit)*N_trials*(h.BinWidth); plot(ax,x_fit,y_fit,'r-','LineWidth',2); hold(ax,'off'); txt_str = sprintf('%.2f \\pm %.2f MPa',meanPr,stdPr); text(ax,0.15,0.90,txt_str,'Units','normalized','FontName','Arial','FontSize',10); if iD == 1 title(ax,sprintf('%d',rho_val),'FontName','Arial','FontSize',22,'FontWeight', 'bold'); end if irho == 1 ylabel(ax,sprintf('%d',D_val),'FontName','Arial','FontSize',22,'FontWeight', 'bold'); end if iD == n_D xlabel(ax,'Residual pressure (MPa)','FontName','Arial','FontSize',10); end y_lim_auto = ax.YLim; ylim(ax, [0, y_lim_auto(2)*1.2]); set(ax, 'FontSize', 10, 'FontName','Arial', 'LineWidth',1.2,... 'TickDir','out','TickLength',[0.015 0.015]); end end lgd = legend(ax,{'Frequency counts','Gauss fit'},'Location','southoutside','Orientation','horizontal'); lgd.Layout.Tile = 'south'; lgd.FontName='Arial';lgd.FontSize=12; lgd = legend(ax,{'Frequency counts','Gauss fit'},'Location','southoutside','Orientation','horizontal'); lgd.Layout.Tile = 'south'; lgd.FontName='Arial';lgd.FontSize=12; exportgraphics(fig, 'Volcano_Model_1_Pr_Distribution.png', ... 'Resolution', 300); case 2 % ============================================================== % Case 2: Random Magma Temperature (Tmag only) % ============================================================== fprintf('\n===== Running: Random Magma Temperature (Tmag only) =====\n'); % --- Case-specific parameter configuration --- %% ===================== Global parameter configuration ===================== N_trials = 10000; % 10000 Monte Carlo trials per group rho_list = [2600,2700,2800,2900,3000]; % Columns: crustal density D_list = [10,30,50,70,90]; % Rows: crustal thickness % ========== Fixed parameters ========== E_fixed = 55; % Fixed Young's modulus, GPa (midpoint of original E range) H_fixed = (7.5 + 15.8)/2; % Fixed melt zone thickness, km (midpoint of range) % ========== Random variable: Magma temperature ========== Tmag_C_min = 1043; % Lower bound of magma temperature, ℃ Tmag_C_max = 1185; % Upper bound of magma temperature, ℃ % ========== Viscosity-temperature relation parameters (Arrhenius equation) ========== % Reference point: pure magma viscosity μ₀=151.4 Pa·s at 1114℃ from literature T_ref_C = 1114; % Reference temperature, ℃ mu0_ref = 151.4; % Pure magma viscosity at reference temperature, Pa·s Ea_over_R = 30000; % Viscous activation energy / gas constant, K (typical basalt value 24000~36000, adjustable) T_ref_K = T_ref_C + 273.15; % Reference absolute temperature, K % Crystal viscosity formula parameters (literature S3) phi = 0.55; % Crystal volume fraction phi0 = 0.64; % Viscosity crystal constant C = 3; % Viscosity crystal constant exponent_mu = C * phi0 / (1 - phi0); % ========== Wall rock geothermal gradient lookup table against crustal density (literature values) ========== % rho: 2600 2700 2800 2900 3000 % dT(℃/km): 16 15.4 14.9 14.4 13.9 dTwr_Cperkm_list = [16, 15.4, 14.9, 14.4, 13.9]; dTwr_Kperm_list = dTwr_Cperkm_list / 1000; % Unit conversion: ℃/km → K/m n_rho = length(rho_list); n_D = length(D_list); Pr_all = zeros(n_D, n_rho, N_trials); % D(rows),rho(columns),samples %% ========== Serial Monte Carlo loop ========== for iD = 1:n_D D = D_list(iD); for irho = 1:n_rho rho = rho_list(irho); dTwr_dx = dTwr_Kperm_list(irho); % Fetch temperature gradient corresponding to current density fprintf('Calculating D=%d km, rho=%d kg/m3, dTwr/dx=%.4f K/m\n',D,rho,dTwr_dx); for it = 1:N_trials % 1. Sample magma temperature Tmag_C_samp = unifrnd(Tmag_C_min, Tmag_C_max); Tmag_K_samp = Tmag_C_samp + 273.15; % 2. Arrhenius equation to compute pure magma viscosity μ₀ at current temperature mu0_samp = mu0_ref * exp( Ea_over_R * (1/Tmag_K_samp - 1/T_ref_K) ); % 3. Literature S3 formula for crystal-bearing magma viscosity μₘ etam_samp = mu0_samp * ((1 - phi) / (1 - phi0))^exponent_mu; % 4. Call volcanic physics model to calculate residual pressure [Pr,~,~,~] = VolcPhyModel(E_fixed, etam_samp, H_fixed, rho, D, dTwr_dx); Pr_all(iD,irho,it) = Pr; end end end %% ===================== Plot 5×5 subplot array (format fully consistent with OnlyE version) ===================== fig = figure('Color','w','Position',[100,100,1200,1200]); t = tiledlayout(n_D,n_rho,'TileSpacing','compact','Padding','compact'); title(t,'Crustal density (kg m^{-3})','FontSize',16,'FontName','Arial','FontWeight', 'bold'); ylabel(t,'Crustal thickness (km)','FontSize',16,'FontName','Arial','FontWeight', 'bold'); for iD = 1:n_D D_val = D_list(iD); for irho = 1:n_rho rho_val = rho_list(irho); ax = nexttile; Pr_sample = squeeze(Pr_all(iD,irho,:)); meanPr = mean(Pr_sample); stdPr = std(Pr_sample); h = histogram(ax,Pr_sample,20); h.FaceColor = [0.75,0.76,0.87]; h.EdgeColor = [0.2,0.2,0.2]; hold(ax,'on'); pd = fitdist(Pr_sample,'Normal'); x_fit = linspace(min(Pr_sample),max(Pr_sample),200); y_fit = pdf(pd,x_fit)*N_trials*(h.BinWidth); plot(ax,x_fit,y_fit,'r-','LineWidth',2); hold(ax,'off'); txt_str = sprintf('%.2f \\pm %.2f MPa',meanPr,stdPr); text(ax,0.15,0.90,txt_str,'Units','normalized','FontName','Arial','FontSize',10); if iD == 1 title(ax,sprintf('%d',rho_val),'FontName','Arial','FontSize',22,'FontWeight', 'bold'); end if irho == 1 ylabel(ax,sprintf('%d',D_val),'FontName','Arial','FontSize',22,'FontWeight', 'bold'); end % Add x-axis label for bottom-row subplots if iD == n_D xlabel(ax,'Residual pressure (MPa)','FontName','Arial','FontSize',10); end y_lim_auto = ax.YLim; ylim(ax, [0, y_lim_auto(2)*1.2]); set(ax, 'FontSize', 10, 'FontName','Arial', 'LineWidth',1.2,... 'TickDir','out','TickLength',[0.015 0.015]); end end lgd = legend(ax,{'Frequency counts','Gauss fit'},'Location','southoutside','Orientation','horizontal'); lgd.Layout.Tile = 'south'; lgd.FontName='Arial';lgd.FontSize=12; lgd = legend(ax,{'Frequency counts','Gauss fit'},'Location','southoutside','Orientation','horizontal'); lgd.Layout.Tile = 'south'; lgd.FontName='Arial';lgd.FontSize=12; exportgraphics(fig, 'Volcano_Model_2_Pr_Distribution.png', ... 'Resolution', 300); case 3 % ============================================================== % Case 3: Random Melt Zone Thickness (H only) % ============================================================== fprintf('\n===== Running: Random Melt Zone Thickness (H only) =====\n'); % --- Case-specific parameter configuration --- N_trials = 10000; % 10000 Monte Carlo trials per group rho_list = [2600,2700,2800,2900,3000]; % Columns: crustal density D_list = [10,30,50,70,90]; % Rows: crustal thickness % ========== Fixed parameters ========== E_fixed = 55; % Fixed Young's modulus, GPa (midpoint of original E range) % Fixed magma temperature: pre-eruption temperature 1114℃ from literature, corresponding to pure magma viscosity μ₀=151.4 Pa·s mu0 = 151.4; % Pure magma viscosity at fixed temperature, Pa·s phi = 0.55; % Crystal volume fraction phi0 = 0.64; % Viscosity crystal constant C = 3; % Viscosity crystal constant exponent_mu = C * phi0 / (1 - phi0); etam_fixed = mu0 * ((1 - phi) / (1 - phi0))^exponent_mu; % Fixed viscosity of crystal-bearing magma fprintf('Fixed magma viscosity etam = %.4e Pa·s\n',etam_fixed); % ========== Sole random variable: Melt zone thickness H ========== H_min = 7.5; % Lower bound of melt zone thickness, km H_max = 15.8; % Upper bound of melt zone thickness, km % ========== Wall rock geothermal gradient lookup table against crustal density ========== % rho: 2600 2700 2800 2900 3000 % dT(℃/km): 16 15.4 14.9 14.4 13.9 dTwr_Cperkm_list = [16, 15.4, 14.9, 14.4, 13.9]; dTwr_Kperm_list = dTwr_Cperkm_list / 1000; % Unit conversion: ℃/km → K/m n_rho = length(rho_list); n_D = length(D_list); Pr_all = zeros(n_D, n_rho, N_trials); % D(rows),rho(columns),samples %% ========== Serial Monte Carlo loop ========== for iD = 1:n_D D = D_list(iD); for irho = 1:n_rho rho = rho_list(irho); dTwr_dx = dTwr_Kperm_list(irho); % Fetch temperature gradient corresponding to current density fprintf('Calculating D=%d km, rho=%d kg/m3, dTwr/dx=%.4f K/m\n',D,rho,dTwr_dx); for it = 1:N_trials % Sample melt zone thickness H_samp = unifrnd(H_min, H_max); % Call volcanic physics model to calculate residual pressure [Pr,~,~,~] = VolcPhyModel(E_fixed, etam_fixed, H_samp, rho, D, dTwr_dx); Pr_all(iD,irho,it) = Pr; end end end %% ===================== Plot 5×5 subplot array ===================== fig = figure('Color','w','Position',[100,100,1200,1200]); t = tiledlayout(n_D,n_rho,'TileSpacing','compact','Padding','compact'); title(t,'Crustal density (kg m^{-3})','FontSize',16,'FontName','Arial','FontWeight', 'bold'); ylabel(t,'Crustal thickness (km)','FontSize',16,'FontName','Arial','FontWeight', 'bold'); for iD = 1:n_D D_val = D_list(iD); for irho = 1:n_rho rho_val = rho_list(irho); ax = nexttile; Pr_sample = squeeze(Pr_all(iD,irho,:)); meanPr = mean(Pr_sample); stdPr = std(Pr_sample); h = histogram(ax,Pr_sample,20); h.FaceColor = [0.77,0.88,0.71]; h.EdgeColor = [0.2,0.2,0.2]; hold(ax,'on'); pd = fitdist(Pr_sample,'Normal'); x_fit = linspace(min(Pr_sample),max(Pr_sample),200); y_fit = pdf(pd,x_fit)*N_trials*(h.BinWidth); plot(ax,x_fit,y_fit,'r-','LineWidth',2); hold(ax,'off'); txt_str = sprintf('%.2f \\pm %.2f MPa',meanPr,stdPr); text(ax,0.15,0.90,txt_str,'Units','normalized','FontName','Arial','FontSize',10); if iD == 1 title(ax,sprintf('%d',rho_val),'FontName','Arial','FontSize',22,'FontWeight', 'bold'); end if irho == 1 ylabel(ax,sprintf('%d',D_val),'FontName','Arial','FontSize',22,'FontWeight', 'bold'); end if iD == n_D xlabel(ax,'Residual pressure (MPa)','FontName','Arial','FontSize',10); end y_lim_auto = ax.YLim; ylim(ax, [0, y_lim_auto(2)*1.2]); set(ax, 'FontSize', 10, 'FontName','Arial', 'LineWidth',1.2,... 'TickDir','out','TickLength',[0.015 0.015]); end end lgd = legend(ax,{'Frequency counts','Gauss fit'},'Location','southoutside','Orientation','horizontal'); lgd.Layout.Tile = 'south'; lgd.FontName='Arial';lgd.FontSize=12; lgd = legend(ax,{'Frequency counts','Gauss fit'},'Location','southoutside','Orientation','horizontal'); lgd.Layout.Tile = 'south'; lgd.FontName='Arial';lgd.FontSize=12; exportgraphics(fig, 'Volcano_Model_3_Pr_Distribution.png', ... 'Resolution', 300); case 4 % ============================================================== % Case 4: All Three Parameters Random % ============================================================== fprintf('\n===== Running: All Three Parameters Random =====\n'); % --- Case-specific parameter configuration --- N_trials = 10000; % 10000 Monte Carlo trials per group rho_list = [2600,2700,2800,2900,3000]; % Columns: crustal density D_list = [10,30,50,70,90]; % Rows: crustal thickness % ========== Value ranges for three random variables ========== E_min = 10; E_max = 100; % Sampling range of Young's modulus, GPa Tmag_C_min = 1043; Tmag_C_max = 1185;% Sampling range of magma temperature, ℃ H_min = 7.5; H_max = 15.8; % Sampling range of melt zone thickness, km % ========== Definition of optimal parameters ========== % === E takes mode (midpoint) of range, Tmag takes mode (midpoint) of range, H takes maximum === E_opt = (E_min + E_max) / 2; % Mode of Young's modulus: midpoint of interval (peak for uniform distribution) Tmag_opt_C = (Tmag_C_min + Tmag_C_max) / 2; % Mode of magma temperature: midpoint of interval, corresponding to viscosity mode H_opt = H_max; % Melt zone thickness: maximum value 15.8 km % ========== Viscosity-temperature relation parameters ========== T_ref_C = 1114; % Reference temperature set to interval midpoint, consistent with optimal temperature mu0_ref = 151.4; % Pure magma viscosity at reference temperature, Pa·s Ea_over_R = 30000; % Viscous activation energy / gas constant, K (typical basalt value to guarantee reasonable viscosity variation over temperature range) T_ref_K = T_ref_C + 273.15; % Reference absolute temperature, K % Crystal viscosity formula parameters phi = 0.55; % Crystal volume fraction phi0 = 0.64; % Viscosity crystal constant C = 3; % Viscosity crystal constant exponent_mu = C * phi0 / (1 - phi0); % ========== Wall rock geothermal gradient lookup table against crustal density ========== % rho: 2600 2700 2800 2900 3000 % dT(℃/km): 16 15.4 14.9 14.4 13.9 dTwr_Cperkm_list = [16, 15.4, 14.9, 14.4, 13.9]; dTwr_Kperm_list = dTwr_Cperkm_list / 1000; % Unit conversion: ℃/km → K/m n_rho = length(rho_list); n_D = length(D_list); Pr_all = zeros(n_D, n_rho, N_trials); % D(rows),rho(columns),samples Pr_opt = zeros(n_D, n_rho); % Baseline Pr value for each (D,ρ) under optimal parameters %% ========== Pre-calculate: baseline Pr under optimal parameters ========== Tmag_opt_K = Tmag_opt_C + 273.15; mu0_opt = mu0_ref * exp( Ea_over_R * (1/Tmag_opt_K - 1/T_ref_K) ); etam_opt = mu0_opt * ((1 - phi) / (1 - phi0))^exponent_mu; for iD = 1:n_D D = D_list(iD); for irho = 1:n_rho rho = rho_list(irho); dTwr_dx = dTwr_Kperm_list(irho); Pr_opt(iD,irho) = VolcPhyModel(E_opt, etam_opt, H_opt, rho, D, dTwr_dx); end end %% ========== Serial Monte Carlo loop (three parameters random simultaneously) ========== for iD = 1:n_D D = D_list(iD); for irho = 1:n_rho rho = rho_list(irho); dTwr_dx = dTwr_Kperm_list(irho); fprintf('Calculating D=%d km, rho=%d kg/m³\n',D,rho); for it = 1:N_trials % 1. Sample three random parameters simultaneously E_samp = unifrnd(E_min, E_max); Tmag_C_samp = unifrnd(Tmag_C_min, Tmag_C_max); H_samp = unifrnd(H_min, H_max); % 2. Calculate magma viscosity at current temperature Tmag_K_samp = Tmag_C_samp + 273.15; mu0_samp = mu0_ref * exp( Ea_over_R * (1/Tmag_K_samp - 1/T_ref_K) ); etam_samp = mu0_samp * ((1 - phi) / (1 - phi0))^exponent_mu; % 3. Call model to compute residual pressure Pr = VolcPhyModel(E_samp, etam_samp, H_samp, rho, D, dTwr_dx); Pr_all(iD,irho,it) = Pr; end end end %% ===================== Plot 5×5 subplot array ===================== fig = figure('Color','w','Position',[100,100,1200,1200]); t = tiledlayout(n_D,n_rho,'TileSpacing','compact','Padding','compact'); title(t,'Crustal density (kg m^{-3})','FontSize',16,'FontName','Arial','FontWeight', 'bold'); ylabel(t,'Crustal thickness (km)','FontSize',16,'FontName','Arial','FontWeight', 'bold'); for iD = 1:n_D D_val = D_list(iD); for irho = 1:n_rho rho_val = rho_list(irho); ax = nexttile; Pr_sample = squeeze(Pr_all(iD,irho,:)); meanPr = mean(Pr_sample); stdPr = std(Pr_sample); Pr_opt_val = Pr_opt(iD,irho); % Pr value calculated from optimal parameters, x-coordinate of pentagram h = histogram(ax,Pr_sample,20); h.FaceColor = [0.12, 0.47, 0.85]; h.EdgeColor = [0.2, 0.2, 0.2]; hold(ax,'on'); bin_width = h.BinWidth; pd = fitdist(Pr_sample,'Normal'); x_fit = linspace(min(Pr_sample),max(Pr_sample),200); y_fit = pdf(pd,x_fit)*N_trials*bin_width; plot(ax,x_fit,y_fit,'r-','LineWidth',2); % ========== pentagram plotted strictly on Gaussian fitting curve ========== % Compute Gaussian fit frequency (y-coordinate) corresponding to optimal Pr value y_fit_opt = pdf(pd, Pr_opt_val) * N_trials * bin_width; plot(ax, Pr_opt_val, y_fit_opt, 'p', ... 'MarkerSize', 12, ... 'MarkerFaceColor', [1.0, 0.6, 0.0], ... % Orange pentagram 'MarkerEdgeColor', [0.8, 0.4, 0.0]); % Quantile annotation: placed at upper-right of pentagram quantile_pct = sum(Pr_sample <= Pr_opt_val) / N_trials * 100; text(ax, Pr_opt_val + (max(Pr_sample)-min(Pr_sample))*0.02, y_fit_opt*1.05, ... sprintf('%.1f%%', quantile_pct), ... 'FontSize',9, 'FontName','Arial','FontWeight','bold', 'VerticalAlignment','bottom'); text(ax, 0.5, 0.92, ... sprintf('%.2f ± %.2f MPa',meanPr,stdPr), ... 'Units','normalized', 'HorizontalAlignment','center', ... 'FontName','Arial','FontSize',10); if iD == 1 title(ax,sprintf('%d',rho_val),... 'FontName','Arial','FontSize',22,'FontWeight', 'bold'); end if irho == 1 ylabel(ax,sprintf('%d',D_val),... 'FontName','Arial','FontSize',22,'FontWeight', 'bold'); end if iD == n_D xlabel(ax,'Residual pressure (MPa)',... 'FontName','Arial','FontSize',10); end y_lim_auto = ax.YLim; ylim(ax, [0, y_lim_auto(2)*1.2]); set(ax, 'FontSize', 10, 'FontName','Arial', 'LineWidth',1.2,... 'TickDir','out','TickLength',[0.015 0.015]); hold(ax,'off'); end end lgd = legend(ax,{'Frequency counts','Gauss fit','The optimal solution'},... 'Location','southoutside','Orientation','horizontal'); lgd.Layout.Tile = 'south'; lgd.FontName='Arial';lgd.FontSize=12; lgd = legend(ax,{'Frequency counts','Gauss fit','The optimal solution'},... 'Location','southoutside','Orientation','horizontal'); lgd.Layout.Tile = 'south'; lgd.FontName='Arial';lgd.FontSize=12; exportgraphics(fig, 'Volcano_Model_4_Pr_Distribution.png', ... 'Resolution', 300); otherwise error('Invalid input. Please enter an integer between 1 and 4.'); end