How can I change the title of a figure through each iteration of the loop?
조회 수: 12 (최근 30일)
이전 댓글 표시
I have the following Matlab code that gives me four figures.
close all;
clear variables;
clc;
% % 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
The problem is all four figures will have the same title. In the above code, each iteration gives me 2 figures. So I need to change the title of every two figures at each new iteration:
Therefore, for the first iteration, I need the following title
title({ 'The coverage area' ;[ '\phi = \pm10' , '\psi = \pm10' , 'FEC = 3.8\times10^{-3}' ]});
For the second iteration, I need the following title
title({ 'The coverage area' ;[ '\phi = \pm10' , '\psi = \pm10' , 'FEC =10^{-5}' ]});
댓글 수: 2
Rasha Shamite
2022년 12월 19일
Hello,please ,send me massage at my email,''rashasalman19871987@gmail.com''
답변 (1개)
VBBV
2022년 11월 27일
편집: VBBV
2022년 11월 27일
close all;
clear variables;
clc;
% % 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(i) % use iterator index
subplot(211)
% 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 ;
subplot(212)
% 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
댓글 수: 4
VBBV
2022년 11월 27일
Ok. Then you need to use
if i == 1
figure
....
title({ 'The coverage area' ;[ '\phi = \pm10' , '\psi = \pm10' , 'FEC = 3.8\times10^{-3}' ]});
figure
...
title({ 'The coverage area' ;[ '\phi = \pm10' , '\psi = \pm10' , 'FEC = 3.8\times10^{-3}' ]});
else
figure
...
title({ 'The coverage area' ;[ '\phi = \pm10' , '\psi = \pm10' , 'FEC =10^{-5}' ]});
figure
...
title({ 'The coverage area' ;[ '\phi = \pm10' , '\psi = \pm10' , 'FEC =10^{-5}' ]});
end
Then You need to use and if-else condition inside for loop as above
참고 항목
카테고리
Help Center 및 File Exchange에서 Results, Reporting, and Test File Management에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!