필터 지우기
필터 지우기

How can i mark the data points in the graph?

조회 수: 2 (최근 30일)
Md Monirul Islam
Md Monirul Islam 2017년 3월 13일
댓글: Star Strider 2017년 3월 14일
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])

채택된 답변

Star Strider
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')
Another is to use a text (link) object. See the documentation for details.
  댓글 수: 2
Md Monirul Islam
Md Monirul Islam 2017년 3월 14일
thanks for your answer. but i was looking for pinpointing each data with label. e.g. for the first data point (0,1) of figure 1, i want the point be labeled as (0,1) so that i can see what that point refers to in my data.
Star Strider
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 CenterFile Exchange에서 Graphics Objects에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by