Azzera filtri
Azzera filtri

How can i mark the data points in the graph?

2 visualizzazioni (ultimi 30 giorni)
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])

Risposta accettata

Star Strider
Star Strider il 13 Mar 2017
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 Commenti
Md Monirul Islam
Md Monirul Islam il 14 Mar 2017
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 il 14 Mar 2017
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.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Graphics Objects in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by