![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1148620/image.png)
How can I set x ticks for every curve in the subplot, legend for every curve and a title for the whole figure?
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Haitham AL Satai
am 7 Okt. 2022
Kommentiert: Les Beckham
am 7 Okt. 2022
I have the following figure with 12 curves superimposed on each other, as shown below.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1148495/image.png)
I want to draw each curve alone with a subplot as shown below
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1148560/image.png)
I would like to put for every curve legend from the ones in the first figure (i.e., the first curve 5, the second one 10, ..., till 60) and x ticks like the one in the first figure (16, 32, ..., 1024) and title for the whole figure.
My try below:
Q = [16,32,64,128,256,512,1024];
VEC_Beam_5 = [113.2659 69.7204 51.8739 34.5033 21.6538 10.9459 5.9488]; % Coverage area of Theta = 5
VEC_Beam_10 = [117.5491 76.1452 53.3016 38.3105 23.0815 13.5634 6.9007]; % Coverage area of Theta = 10
VEC_Beam_15 = [117.5491 76.1452 53.3016 38.3105 23.0815 13.5634 6.9007]; % Coverage area of Theta = 15
VEC_Beam_20 = [117.7870 76.1452 53.3016 38.5485 23.0815 13.5634 6.9007]; % Coverage area of Theta = 20
VEC_Beam_25 = [117.7870 76.6211 54.2534 38.5485 23.0815 13.5634 6.9007]; % Coverage area of Theta = 25
VEC_Beam_30 = [117.7870 76.6211 54.2534 38.5485 23.0815 13.5634 6.9007]; % Coverage area of Theta = 30
VEC_Beam_35 = [117.7870 76.6211 54.2534 38.5485 23.0815 13.5634 6.9007]; % Coverage area of Theta = 35
VEC_Beam_40 = [117.7870 76.6211 54.2534 38.5485 23.0815 13.5634 6.9007]; % Coverage area of Theta = 40
VEC_Beam_45 = [117.7870 76.6211 54.2534 38.7864 23.0815 13.5634 6.9007]; % Coverage area of Theta = 45
VEC_Beam_50 = [117.7870 76.6211 54.2534 38.7864 23.0815 13.5634 6.9007]; % Coverage area of Theta = 50
VEC_Beam_55 = [117.7870 76.6211 54.2534 38.7864 23.0815 13.5634 6.9007]; % Coverage area of Theta = 55
VEC_Beam_60 = [117.7870 76.6211 54.2534 38.7864 23.0815 13.5634 6.9007]; % Coverage area of Theta = 60
VEC_Beam = [VEC_Beam_5;VEC_Beam_10;VEC_Beam_15;VEC_Beam_20;VEC_Beam_25;VEC_Beam_30;VEC_Beam_35;VEC_Beam_40;VEC_Beam_45;VEC_Beam_50;VEC_Beam_55;VEC_Beam_60];
figure
cmap = jet(12);
hold on
for k = 1:12
plot(log2(Q),VEC_Beam(k,:), 'Color', cmap(k, :),'LineWidth',2, 'Marker','O');
end
hold off
xticks(log2(Q))
xticklabels(string(Q))
xlabel('Q');
ylabel('Coverage area');
title('Beam');
legstr= "\theta_1_/_2 = "+(5:5:60)+"°";
legend(legstr)
grid on;
figure
cmap = jet(12);
hold on
for k1 = 1:12
subplot(2,6,k1)
plot(log2(Q),VEC_Beam(k1,:), 'Color', cmap(k1, :),'LineWidth',2, 'Marker','O');
xticks(log2(Q))
xlabel('Q');
ylabel('Coverage area');
grid on;
legstr= "\theta_1_/_2 = "+(5)+"°";
legend(legstr)
end
0 Kommentare
Akzeptierte Antwort
Les Beckham
am 7 Okt. 2022
Bearbeitet: Les Beckham
am 7 Okt. 2022
It looks like it works just fine except for the legend.
Instead of
legstr= "\theta_1_/_2 = "+(5)+"°";
try this
legstr= "\theta_1_/_2 = " + (5 + 5*(k1-1)) + "°";
With that change I get this figure
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1148620/image.png)
As far as adding a title for the entire figure, I'm not sure how to do that unless you change to using tiledlayout instead of subplots. If you do that, you pass the handle to the tiledlayout to the title function.
2 Kommentare
Les Beckham
am 7 Okt. 2022
You are quite welcome. I had forgotten about sgtitle. Thanks for the reminder.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Discrete Data Plots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!