How can i mark the data points in the graph?
2 次查看(过去 30 天)
显示 更早的评论
I've plotted this figure. Now i want to mark the corresponding points. my code is
clc;
close all;
clear all;
x=[0:1:12];
SWR_Ratio=[1,1.28,1.8,2.5,3.2,4.2,5.4,7.25,10,11.32,11.8,12.85,20];
SWR_Deflection=[0,2.2,5,7.5,10,12.5,14.5,17.5,20,22.2,25.1,28.5,30];
figure(1)
subplot('211')
loglog(x,SWR_Ratio,'r')
title('Standing Wave Ratio (SWR) vs Attenuation')
xlabel('Attenuation(dB)')
ylabel('SWR')
grid on
subplot('212')
semilogx(x,SWR_Deflection)
title('SWR deflection vs Attenuation')
% legend('semilogx')
xlabel('Attenuation(dB)')
ylabel('SWR deflection')
axis([0 100 0 100])
0 个评论
采纳的回答
Star Strider
2017-3-13
You do not say how you want to ‘mark the corresponding points’.
Two possibilities:
One is to include a marker with the plot:
loglog(x,SWR_Ratio,'-rp')
and:
semilogx(x,SWR_Deflection, '-p')
2 个评论
Star Strider
2017-3-14
My pleasure.
Use the text function for that. (I already linked to it in my original Answer.) It has a number of name-value pairs that will allow you align each one correctly.
This works:
x=[0:1:12];
SWR_Ratio=[1,1.28,1.8,2.5,3.2,4.2,5.4,7.25,10,11.32,11.8,12.85,20];
SWR_Deflection=[0,2.2,5,7.5,10,12.5,14.5,17.5,20,22.2,25.1,28.5,30];
figure(1)
subplot('211')
loglog(x,SWR_Ratio,'r')
title('Standing Wave Ratio (SWR) vs Attenuation')
xlabel('Attenuation(dB)')
ylabel('SWR')
grid on
pt_str = sprintf('(%d,%g)\n', [x(:) SWR_Ratio(:)]');
pt_cell = regexp(pt_str, '\n', 'split');
text(x, SWR_Ratio, pt_cell(1:end-1), 'HorizontalAlignment','left', 'VerticalAlignment','bottom', 'FontSize',8)
subplot('212')
semilogx(x,SWR_Deflection)
title('SWR deflection vs Attenuation')
% legend('semilogx')
xlabel('Attenuation(dB)')
ylabel('SWR deflection')
axis([0 100 0 100])
pt_str = sprintf('(%d,%g)\n', [x(:) SWR_Deflection(:)]');
pt_cell = regexp(pt_str, '\n', 'split');
text(x, SWR_Deflection, pt_cell(1:end-1), 'HorizontalAlignment','left', 'VerticalAlignment','bottom', 'FontSize',8)
The ‘pt_str’ assignment creates the point label string, ‘pt_cell’ creates a cell array from them because the text function wants them as a cell array (the last entry is blank, so I removed it with the ‘(1:end-1)’ subscript reference), and the text call plots the labels.
You will have to experiment to get the labels to display as you want them to.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Annotations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!