How to combine three different figures for three different vectors in one figure?

16 ビュー (過去 30 日間)
Atrolita afra
Atrolita afra 2020 年 10 月 18 日
回答済み: Satwik 2025 年 3 月 24 日
Here, for a = 9.1 or 3.99 or 1.1 and b = 4 or 2 or 2 i can get one single plot where i am verying another variable segma. But i want to combine them in one figure. so that i can compare them from one plot.
clc
clear variables
close all
M=16;
segma_N = 10.^-7;
p_db = 0:5:30;
p = 10.^(p_db/10);%power
R = 0.5; %Optoelectronic conversion factor
a = 9.1; %a=[9.1 3.99 1.1];
b = 4; %b=[4 2 2
];
rng(1);
I = abs(random('normal',1,2,1,100,1))*1e-8;
%segma =[(0.0647*0.115129255) (0.7360*0.115129255) (4.2850*0.115129255)];
segma =[0.4472 1.264 1.870];
nz = zeros(1, length(p_db));
%ze = zeros(1, length(p_db));
for k=1:length(segma)
for j = 1:length(nz)
ynz = qfunc(sqrt(2*((p(j).*R.*I)./segma_N).^2)).*nzpdf(I,segma(k)); %Bpsk
nz(k,j) = trapz(I, ynz);
end
end
% Plot
figure
semilogy(p_db,nz(1,:),'-ks','MarkerFaceColor','k')
hold on
semilogy(p_db,nz(2,:),'-ro','MarkerFaceColor','r')
semilogy(p_db,nz(3,:),'-b^','MarkerFaceColor','b')
grid on
xlabel('P [dB]')
ylabel('ABER')
title('Intial Results')
legend('Very clear air','Haze','Light fog')
xlim([0 30])
grid on
for the function nzpdf
function G = nzpdf(I,segma)
a = 9.1;
b = 4;
c = 0.2; %Gamma %Average optical power of classic scattering component received by off-axis eddies
%d =0.8; %Big omega prime Average optical power of coherent contributions
p_db = 0:5:30;
P= 10.^(p_db/10);%power
z = 2; %Propagation Distance
%segma = (8*0.115129255); %Atmospheric attenuation coefficient
%segma =(4.2850*0.115129255);
s = 0.3; %Zero boresight
I1 = exp(-segma*z); %Atmospheric attenuation
omega=1.3265;
b_0=0.1079; %Average power of the coupled-to-LOS scattering component
row=0.25; %Scattering power coupled to the LOS component
d=(omega+row.*2.*b_0+2.*sqrt(2.*b_0.*omega.*row));%Big omega prime Average optical power of coherent contributio
Aperture_radius = 0.1; %Aperture_radius
segma_s = 0.2; %Jitter standard deviation
omega_z = 2.5; %Beam Width
v = (sqrt(pi)*Aperture_radius)/(sqrt(2)*omega_z);
omega_zeq_2 = (omega_z^2)*(sqrt(pi)*erf(v))/(2*v*exp(-(v^2)));
g = omega_zeq_2/(2*segma_s);
A0 = (erf(v))^2;
A = (2*(a^(a/2))/((c^(1+a/2))*gamma(a)))*(((c*b)/(c*b+d))^(b+a/2));
First = (2*pi*(g^2)*A*exp((-(s^2))/(2*(segma_s^2))))/(omega_zeq_2);
count1 = 0;
for k= 1:b
ak = (nchoosek(b-1,k-1))*(((c*b+d)^(1-k/2))/gamma(k))*((d/c)^(k-1))*((a/b)^(k/2));
Summation_1 = ak*(I.^(((a+k)/2)-1)) / ( ((A0*I1)^((a+k)/2)) * sin(pi*(a-k)) );
count2 = 0;
for p = 0:length(P)
Part1 = (((a*b.*I)/((c*b+d)*A0*I1)).^(p-(a-k)/2)) / (gamma(p-(a-k)+1)*factorial(floor(p)));
Part2_1 = (-omega_zeq_2) / ((4*(p+k-(g^2))));
Part2_2 = exp(((-omega_zeq_2)*(s^2)) /(8*(p+k-(g^2))*segma_s^4));
Sum1 = Part1 .* (Part2_1 *Part2_2);
Part3 = (((a*b.*I)/((c*b+d)*A0*I1)).^(p+(a-k)/2)) / (gamma(p+(a-k)+1)*factorial(floor(p)));
Part4_1 = (-omega_zeq_2) / ((4*(p+a-(g^2))));
Part4_2 = exp(((-omega_zeq_2)*(s^2)) / (8*(p+a-g^2)*segma_s^4));
Min1 = Part3.*( Part4_1*Part4_2);
Summation_2 = Sum1 - Min1;
count2 = count2 + Summation_2;
end
count1 = count1 + count2.*Summation_1;
end
G = First.*count1;
end

回答 (1 件)

Satwik
Satwik 2025 年 3 月 24 日
To combine multiple plots into a single figure for comparison, loop over the values of 'a' and 'b' and modify the plotting section of the script. Here is a modified version of the script which should help you achieve the desired result:
% Arrays for a and b
a_values = [9.1, 3.99, 1.1];
b_values = [4, 2, 2];
% Initialize results storage
nz_results = zeros(length(a_values), length(segma), length(p_db));
% Loop over a, b, and segma
for idx_a = 1:length(a_values)
a = a_values(idx_a);
b = b_values(idx_a);
for k = 1:length(segma)
for j = 1:length(p_db)
ynz = qfunc(sqrt(2 * ((p(j) * R * I) / segma_N).^2)) .* nzpdf(I, segma(k), a, b);
nz_results(idx_a, k, j) = trapz(I, ynz);
end
end
end
% Plot results
% All results are plotted on the same figure for easy comparison.
figure;
hold on;
colors = {'-ks', '-ro', '-b^'};
legends = {'Very clear air', 'Haze', 'Light fog'};
for idx_a = 1:length(a_values)
for k = 1:length(segma)
semilogy(p_db, squeeze(nz_results(idx_a, k, :)), colors{k}, 'MarkerFaceColor', colors{k}(2));
end
end
grid on;
xlabel('P [dB]');
ylabel('ABER');
title('Combined Results');
legend(legends);
xlim([0 30]);
% Modified nzpdf function signature
function G = nzpdf(I, segma, a, b)
% Function body remains the same, but The nzpdf function now accepts
% a and b as parameters to reflect the changes in each iteration.
...
end
The following image depicts the result obtained from the above modifications:

カテゴリ

Help Center および File ExchangePropagation and Channel Models についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by