How to smooth the line curves in the plot?
I’m using the function "smooth" and ”abs” to smooth the line curve (I_para) but can’t acheive the smooth curves in the plot. I used the smooth function previously and got the curve smooth but this time it doesn’t work for my case. Please your help willl be appreciated. Thank you
clear, clc, close all
a_ref = 0.05;
Reff_ref = 20;
z_bottom = 1000:1000:4000;
FOV = [0.2, 0.5, 1, 2, 5, 10];
cloud = ‘Sub’;
for h = 1:length(z_bottom)
main_fig = figure(‘NumberTitle’, ‘off’, ‘Name’, [‘Height ‘, num2str(z_bottom(h)), ‘m’]);
Area = []; % for sort
COLOR = {‘r’, ‘g’, ‘b’, [0.8500 0.3250 0.0980], [0.4660 0.6740 0.1880], [0 0.4470 0.7410]};
ylim_max = 0;
for a = 0.01:0.01:a_ref
for r = 4:Reff_ref
clf(main_fig); % Clear the current figure
subplot(1, 1, 1); % Create subplot for all FOVs
hold on;
for f = 1:length(FOV)
Height = genHeight(z_bottom(h))’;
load([‘MCdatabase_’, cloud, ‘/’, num2str(a), ‘-‘, num2str(r), ‘um/’, num2str(z_bottom(h)), ‘m-‘, num2str(FOV(f)), ‘mrad/I0.mat’]);
load([‘MCdatabase_’, cloud, ‘/’, num2str(a), ‘-‘, num2str(r), ‘um/’, num2str(z_bottom(h)), ‘m-‘, num2str(FOV(f)), ‘mrad/Q0.mat’]);
I_para = abs(1/2 * (I0 + Q0));
I_per = abs(1/2 * (I0 – Q0));
% Plotting all FOV plots on a single figure for each cloud height
plot(Height, smooth(abs(sum(I_para, 2))) .* Height.^2, ‘Color’, COLOR{f}, ‘LineWidth’, 1.5);
hold on
plot(Height, smooth(abs(sum(I_per, 2))) .* Height.^2, ‘Color’, COLOR{f}, ‘LineStyle’, ‘–‘, ‘LineWidth’, 1.5);
title([‘Sub-adiabatic cloud, Height ‘, num2str(z_bottom(h)), ‘m’])
% Add annotation for polarized signals
if f == 1
annotation(‘textbox’, [0.15, 0.15, 0.1, 0.1], ‘String’, ‘P_{perp}’, ‘Color’, ‘k’, ‘EdgeColor’, ‘none’, ‘FontWeight’, ‘bold’, ‘FontSize’, 12);
annotation(‘textbox’, [0.24, 0.5, 0.1, 0.1], ‘String’, ‘P_{midmid}’, ‘Color’, ‘k’, ‘LineStyle’, ‘–‘, ‘EdgeColor’, ‘none’, ‘FontWeight’, ‘bold’, ‘FontSize’, 12);
end
Area = [Area, [z_bottom(h); FOV(f); pi * ((2.5 * cot(FOV(f) * 1e-3/2) + z_bottom(h)) * tan(FOV(f) * 1e-3/2))^2]];
% Calculate the maximum y-axis limit
ylim_max = max(ylim_max, max(sum(I_para, 2) .* Height.^2));
ylim_max = max(ylim_max, max(sum(I_per, 2) .* Height.^2));
end
hold off;
end
end
% Figure settings based on the data
zoom on
xlabel(‘Height of the cloud (m)’,’FontSize’,14,’FontWeight’,’normal’);
ylabel(‘Backscattering signal (Unit)’,’FontSize’,14,’FontWeight’,’normal’);
set(gca,’color’,’w’,’Fontsize’,12,’LineWidth’,1.5,’Fontweight’,’normal’);
set(gca,’box’,’off’,’Fontname’,’Arial’,’Fontsmoothing’,’on’);
% Convert y-axis to logarithmic scale
% set(gca, ‘YScale’, ‘log’);
% Define the offset for increasing x-axis limit
if h == 2
offset = 2; % Offset for h == 2
elseif h == 3
offset = 4; % Offset for h == 3
else
offset = 0; % No offset for other cases
end
% Set x-axis limits and ticks with a difference of 50 for all figures
xlim_min = z_bottom(h);
xlim_max = max(Height) + offset; % Adjusted xlim_max with an offset
% Adjust xticks for last tick visibility
if h == 1
xticks = 1000:50:(max(Height));
elseif h == 2
xticks = [2000:50:(max(Height) + offset)]; % Corrected x-ticks for Figure 2
elseif h == 3
xticks = [3000:50:(max(Height) + offset)]; % Corrected x-ticks for Figure 3
else
xticks = 4000:50:xlim_max;
end
set(gca,’xlim’,[xlim_min, xlim_max],’xtick’,xticks,’ylim’,[0 ylim_max],’ytick’,[0:0.02:ylim_max]);
set(gca,’xgrid’,’on’,’ygrid’,’on’,’gridcolor’,’k’);
% Create legend entries for each FOV value
legend_labels = cell(1, length(FOV) * 2); % Preallocate space for legend labels
for i = 1:length(FOV)
legend_labels{(i-1)*2+1} = [num2str(FOV(i)), ‘mrad’];
legend_labels{(i-1)*2+2} = [num2str(FOV(i)), ‘mrad’];
end
% Plot the legend entries in two rows
legend(legend_labels, ‘Location’, ‘NorthEast’, ‘NumColumns’, 3);
legend boxoff
endI’m using the function "smooth" and ”abs” to smooth the line curve (I_para) but can’t acheive the smooth curves in the plot. I used the smooth function previously and got the curve smooth but this time it doesn’t work for my case. Please your help willl be appreciated. Thank you
clear, clc, close all
a_ref = 0.05;
Reff_ref = 20;
z_bottom = 1000:1000:4000;
FOV = [0.2, 0.5, 1, 2, 5, 10];
cloud = ‘Sub’;
for h = 1:length(z_bottom)
main_fig = figure(‘NumberTitle’, ‘off’, ‘Name’, [‘Height ‘, num2str(z_bottom(h)), ‘m’]);
Area = []; % for sort
COLOR = {‘r’, ‘g’, ‘b’, [0.8500 0.3250 0.0980], [0.4660 0.6740 0.1880], [0 0.4470 0.7410]};
ylim_max = 0;
for a = 0.01:0.01:a_ref
for r = 4:Reff_ref
clf(main_fig); % Clear the current figure
subplot(1, 1, 1); % Create subplot for all FOVs
hold on;
for f = 1:length(FOV)
Height = genHeight(z_bottom(h))’;
load([‘MCdatabase_’, cloud, ‘/’, num2str(a), ‘-‘, num2str(r), ‘um/’, num2str(z_bottom(h)), ‘m-‘, num2str(FOV(f)), ‘mrad/I0.mat’]);
load([‘MCdatabase_’, cloud, ‘/’, num2str(a), ‘-‘, num2str(r), ‘um/’, num2str(z_bottom(h)), ‘m-‘, num2str(FOV(f)), ‘mrad/Q0.mat’]);
I_para = abs(1/2 * (I0 + Q0));
I_per = abs(1/2 * (I0 – Q0));
% Plotting all FOV plots on a single figure for each cloud height
plot(Height, smooth(abs(sum(I_para, 2))) .* Height.^2, ‘Color’, COLOR{f}, ‘LineWidth’, 1.5);
hold on
plot(Height, smooth(abs(sum(I_per, 2))) .* Height.^2, ‘Color’, COLOR{f}, ‘LineStyle’, ‘–‘, ‘LineWidth’, 1.5);
title([‘Sub-adiabatic cloud, Height ‘, num2str(z_bottom(h)), ‘m’])
% Add annotation for polarized signals
if f == 1
annotation(‘textbox’, [0.15, 0.15, 0.1, 0.1], ‘String’, ‘P_{perp}’, ‘Color’, ‘k’, ‘EdgeColor’, ‘none’, ‘FontWeight’, ‘bold’, ‘FontSize’, 12);
annotation(‘textbox’, [0.24, 0.5, 0.1, 0.1], ‘String’, ‘P_{midmid}’, ‘Color’, ‘k’, ‘LineStyle’, ‘–‘, ‘EdgeColor’, ‘none’, ‘FontWeight’, ‘bold’, ‘FontSize’, 12);
end
Area = [Area, [z_bottom(h); FOV(f); pi * ((2.5 * cot(FOV(f) * 1e-3/2) + z_bottom(h)) * tan(FOV(f) * 1e-3/2))^2]];
% Calculate the maximum y-axis limit
ylim_max = max(ylim_max, max(sum(I_para, 2) .* Height.^2));
ylim_max = max(ylim_max, max(sum(I_per, 2) .* Height.^2));
end
hold off;
end
end
% Figure settings based on the data
zoom on
xlabel(‘Height of the cloud (m)’,’FontSize’,14,’FontWeight’,’normal’);
ylabel(‘Backscattering signal (Unit)’,’FontSize’,14,’FontWeight’,’normal’);
set(gca,’color’,’w’,’Fontsize’,12,’LineWidth’,1.5,’Fontweight’,’normal’);
set(gca,’box’,’off’,’Fontname’,’Arial’,’Fontsmoothing’,’on’);
% Convert y-axis to logarithmic scale
% set(gca, ‘YScale’, ‘log’);
% Define the offset for increasing x-axis limit
if h == 2
offset = 2; % Offset for h == 2
elseif h == 3
offset = 4; % Offset for h == 3
else
offset = 0; % No offset for other cases
end
% Set x-axis limits and ticks with a difference of 50 for all figures
xlim_min = z_bottom(h);
xlim_max = max(Height) + offset; % Adjusted xlim_max with an offset
% Adjust xticks for last tick visibility
if h == 1
xticks = 1000:50:(max(Height));
elseif h == 2
xticks = [2000:50:(max(Height) + offset)]; % Corrected x-ticks for Figure 2
elseif h == 3
xticks = [3000:50:(max(Height) + offset)]; % Corrected x-ticks for Figure 3
else
xticks = 4000:50:xlim_max;
end
set(gca,’xlim’,[xlim_min, xlim_max],’xtick’,xticks,’ylim’,[0 ylim_max],’ytick’,[0:0.02:ylim_max]);
set(gca,’xgrid’,’on’,’ygrid’,’on’,’gridcolor’,’k’);
% Create legend entries for each FOV value
legend_labels = cell(1, length(FOV) * 2); % Preallocate space for legend labels
for i = 1:length(FOV)
legend_labels{(i-1)*2+1} = [num2str(FOV(i)), ‘mrad’];
legend_labels{(i-1)*2+2} = [num2str(FOV(i)), ‘mrad’];
end
% Plot the legend entries in two rows
legend(legend_labels, ‘Location’, ‘NorthEast’, ‘NumColumns’, 3);
legend boxoff
end I’m using the function "smooth" and ”abs” to smooth the line curve (I_para) but can’t acheive the smooth curves in the plot. I used the smooth function previously and got the curve smooth but this time it doesn’t work for my case. Please your help willl be appreciated. Thank you
clear, clc, close all
a_ref = 0.05;
Reff_ref = 20;
z_bottom = 1000:1000:4000;
FOV = [0.2, 0.5, 1, 2, 5, 10];
cloud = ‘Sub’;
for h = 1:length(z_bottom)
main_fig = figure(‘NumberTitle’, ‘off’, ‘Name’, [‘Height ‘, num2str(z_bottom(h)), ‘m’]);
Area = []; % for sort
COLOR = {‘r’, ‘g’, ‘b’, [0.8500 0.3250 0.0980], [0.4660 0.6740 0.1880], [0 0.4470 0.7410]};
ylim_max = 0;
for a = 0.01:0.01:a_ref
for r = 4:Reff_ref
clf(main_fig); % Clear the current figure
subplot(1, 1, 1); % Create subplot for all FOVs
hold on;
for f = 1:length(FOV)
Height = genHeight(z_bottom(h))’;
load([‘MCdatabase_’, cloud, ‘/’, num2str(a), ‘-‘, num2str(r), ‘um/’, num2str(z_bottom(h)), ‘m-‘, num2str(FOV(f)), ‘mrad/I0.mat’]);
load([‘MCdatabase_’, cloud, ‘/’, num2str(a), ‘-‘, num2str(r), ‘um/’, num2str(z_bottom(h)), ‘m-‘, num2str(FOV(f)), ‘mrad/Q0.mat’]);
I_para = abs(1/2 * (I0 + Q0));
I_per = abs(1/2 * (I0 – Q0));
% Plotting all FOV plots on a single figure for each cloud height
plot(Height, smooth(abs(sum(I_para, 2))) .* Height.^2, ‘Color’, COLOR{f}, ‘LineWidth’, 1.5);
hold on
plot(Height, smooth(abs(sum(I_per, 2))) .* Height.^2, ‘Color’, COLOR{f}, ‘LineStyle’, ‘–‘, ‘LineWidth’, 1.5);
title([‘Sub-adiabatic cloud, Height ‘, num2str(z_bottom(h)), ‘m’])
% Add annotation for polarized signals
if f == 1
annotation(‘textbox’, [0.15, 0.15, 0.1, 0.1], ‘String’, ‘P_{perp}’, ‘Color’, ‘k’, ‘EdgeColor’, ‘none’, ‘FontWeight’, ‘bold’, ‘FontSize’, 12);
annotation(‘textbox’, [0.24, 0.5, 0.1, 0.1], ‘String’, ‘P_{midmid}’, ‘Color’, ‘k’, ‘LineStyle’, ‘–‘, ‘EdgeColor’, ‘none’, ‘FontWeight’, ‘bold’, ‘FontSize’, 12);
end
Area = [Area, [z_bottom(h); FOV(f); pi * ((2.5 * cot(FOV(f) * 1e-3/2) + z_bottom(h)) * tan(FOV(f) * 1e-3/2))^2]];
% Calculate the maximum y-axis limit
ylim_max = max(ylim_max, max(sum(I_para, 2) .* Height.^2));
ylim_max = max(ylim_max, max(sum(I_per, 2) .* Height.^2));
end
hold off;
end
end
% Figure settings based on the data
zoom on
xlabel(‘Height of the cloud (m)’,’FontSize’,14,’FontWeight’,’normal’);
ylabel(‘Backscattering signal (Unit)’,’FontSize’,14,’FontWeight’,’normal’);
set(gca,’color’,’w’,’Fontsize’,12,’LineWidth’,1.5,’Fontweight’,’normal’);
set(gca,’box’,’off’,’Fontname’,’Arial’,’Fontsmoothing’,’on’);
% Convert y-axis to logarithmic scale
% set(gca, ‘YScale’, ‘log’);
% Define the offset for increasing x-axis limit
if h == 2
offset = 2; % Offset for h == 2
elseif h == 3
offset = 4; % Offset for h == 3
else
offset = 0; % No offset for other cases
end
% Set x-axis limits and ticks with a difference of 50 for all figures
xlim_min = z_bottom(h);
xlim_max = max(Height) + offset; % Adjusted xlim_max with an offset
% Adjust xticks for last tick visibility
if h == 1
xticks = 1000:50:(max(Height));
elseif h == 2
xticks = [2000:50:(max(Height) + offset)]; % Corrected x-ticks for Figure 2
elseif h == 3
xticks = [3000:50:(max(Height) + offset)]; % Corrected x-ticks for Figure 3
else
xticks = 4000:50:xlim_max;
end
set(gca,’xlim’,[xlim_min, xlim_max],’xtick’,xticks,’ylim’,[0 ylim_max],’ytick’,[0:0.02:ylim_max]);
set(gca,’xgrid’,’on’,’ygrid’,’on’,’gridcolor’,’k’);
% Create legend entries for each FOV value
legend_labels = cell(1, length(FOV) * 2); % Preallocate space for legend labels
for i = 1:length(FOV)
legend_labels{(i-1)*2+1} = [num2str(FOV(i)), ‘mrad’];
legend_labels{(i-1)*2+2} = [num2str(FOV(i)), ‘mrad’];
end
% Plot the legend entries in two rows
legend(legend_labels, ‘Location’, ‘NorthEast’, ‘NumColumns’, 3);
legend boxoff
end smooth_curve MATLAB Answers — New Questions