How to iterate over multiple vectors or using a function to draw multiple vectors without using the same piece of code again and again?
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Haitham AL Satai
le 27 Nov 2022
Modifié(e) : Haitham AL Satai
le 27 Nov 2022
I have below the following 12 vectors:
% FEC = 3.8x10^-3
% % For Phi/Psi = +/-10
CoverageArea_mean_10 = [84.4735,21.1779,6.4247,2.1416];
CoverageArea_min_10 = [98.5128,21.1779,6.9007,2.1416];
CoverageArea_max_10 = [70.1963,19.0363,5.9488,2.1416];
% For Phi/Psi = +/-40
CoverageArea_mean_40 = [0,4.5211,2.3795,0];
CoverageArea_min_40 = [92.5640,21.1779,6.9007,2.1416];
CoverageArea_max_40 = [0,0.4759,0.2380,0];
% FEC = 10^-5
% % For Phi/Psi = +/-10
% CoverageArea_mean_10 = [45.2112,8.8043,1.1898,0];
% CoverageArea_min_10 = [58.7745,10.7079,2.1416,0];
% CoverageArea_max_10 = [38.5485,8.3284,0,0];
% % For Phi/Psi = +/-40
% CoverageArea_mean_40 = [0,0,0,0];
% CoverageArea_min_40 = [53.7775,10.4700,1.4277,0];
% CoverageArea_max_40 = [0,0,0,0];
I want to draw every three vectors in one figure as I did below:
x = [15,30,45,60];
figure
% For Phi/Psi = +/-10
COVERAGE = [CoverageArea_min_10;CoverageArea_mean_10;CoverageArea_max_10];
COVERAGEAREA = [COVERAGE(:,1)';COVERAGE(:,2)';COVERAGE(:,3)';COVERAGE(:,4)'];
bar(x,COVERAGEAREA);
title({'The coverage area';[' \phi = \pm10',' \psi = \pm10',' FEC = 3.8\times10^{-3}']});
xlabel( 'Semi-angle at half power, \Phi_1_/_2 (°)' );
ylabel('Coverage area (m²)');
BarNames = {'min','mean','max'};
legend(BarNames,'Location','best');
grid on;
figure
% For Phi/Psi = +/-40
COVERAGE1 = [CoverageArea_min_40;CoverageArea_mean_40;CoverageArea_max_40];
COVERAGEAREA1 = [COVERAGE1(:,1)';COVERAGE1(:,2)';COVERAGE1(:,3)';COVERAGE1(:,4)'];
bar(x,COVERAGEAREA1);
title({'The coverage area';[' \phi = \pm40',' \psi = \pm40',' FEC = 3.8\times10^{-3}']});
xlabel( 'Semi-angle at half power, \Phi_1_/_2 (°)' );
ylabel('Coverage area (m²)');
BarNames = {'min','mean','max'};
legend(BarNames,'Location','best');
grid on;
The code above will plot the first six vectors in two figures. Now, I need to draw the second 6 vectors in the same manner, but I do not need to write the same above code again. I need to plot all these vectors in the same time every three vectors in one figure. How can I iterrate over them? Or put them in a function to plot them? Any assistance please?
0 commentaires
Réponse acceptée
KALYAN ACHARJYA
le 27 Nov 2022
Modifié(e) : KALYAN ACHARJYA
le 27 Nov 2022
% FEC = 3.8x10^-3
% % For Phi/Psi = +/-10
CoverageArea_mean_10 = {[84.4735,21.1779,6.4247,2.1416],[45.2112,8.8043,1.1898,0]};
CoverageArea_min_10 = {[98.5128,21.1779,6.9007,2.1416],[58.7745,10.7079,2.1416,0]};
CoverageArea_max_10 = {[70.1963,19.0363,5.9488,2.1416],[38.5485,8.3284,0,0]};
% For Phi/Psi = +/-40
CoverageArea_mean_40 = {[0,4.5211,2.3795,0],[0,0,0,0]};
CoverageArea_min_40 = {[92.5640,21.1779,6.9007,2.1416],[53.7775,10.4700,1.4277,0]};
CoverageArea_max_40 = {[0,0.4759,0.2380,0],[0,0,0,0]};
for i=1:2
x = [15,30,45,60];
figure
% For Phi/Psi = +/-10
COVERAGE = [CoverageArea_min_10{i};CoverageArea_mean_10{i};CoverageArea_max_10{i}];
COVERAGEAREA = [COVERAGE(:,1)';COVERAGE(:,2)';COVERAGE(:,3)';COVERAGE(:,4)'];
bar(x,COVERAGEAREA);
title({'The coverage area';[' \phi = \pm10',' \psi = \pm10',' FEC = 3.8\times10^{-3}']});
xlabel( 'Semi-angle at half power, \Phi_1_/_2 (°)' );
ylabel('Coverage area (m²)');
BarNames = {'min','mean','max'};
legend(BarNames,'Location','best');
grid on;
figure
% For Phi/Psi = +/-40
COVERAGE1 = [CoverageArea_min_40{i};CoverageArea_mean_40{i};CoverageArea_max_40{i}];
COVERAGEAREA1 = [COVERAGE1(:,1)';COVERAGE1(:,2)';COVERAGE1(:,3)';COVERAGE1(:,4)'];
bar(x,COVERAGEAREA1);
title({'The coverage area';[' \phi = \pm40',' \psi = \pm40',' FEC = 3.8\times10^{-3}']});
xlabel( 'Semi-angle at half power, \Phi_1_/_2 (°)' );
ylabel('Coverage area (m²)');
BarNames = {'min','mean','max'};
legend(BarNames,'Location','best');
grid on;
end
2 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Gamma Functions dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!