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 ビュー (過去 30 日間)
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?

採用された回答

KALYAN ACHARJYA
KALYAN ACHARJYA 2022 年 11 月 27 日
編集済み: KALYAN ACHARJYA 2022 年 11 月 27 日
% 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 件のコメント
Haitham AL Satai
Haitham AL Satai 2022 年 11 月 27 日
編集済み: Haitham AL Satai 2022 年 11 月 27 日
@KALYAN ACHARJYA Thank you very much sir. Just one small thing, how can I change the title?
title({ 'The coverage area' ;[ '\phi = \pm10' , '\psi = \pm10' , 'FEC = 3.8\times10^{-3}' ]});
Especially this part
'FEC = 3.8\times10^{-3}'
This is because it will be the same for all.
For the first two figures, it must have the following tilte:
title({ 'The coverage area' ;[ '\phi = \pm10' , '\psi = \pm10' , 'FEC = 3.8\times10^{-3}' ]});
On the second two figure it must have the following
title({ 'The coverage area' ;[ '\phi = \pm10' , '\psi = \pm10' , 'FEC =10^{-5}' ]});

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGamma Functions についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by