Sista
Sista

Reputation: 887

Marking a specific point on a graph in MATLAB

I guess this is a very basic question.

I have a graph which I created in MATLAB. This is a graph of Power (y-axis) versus Frequency (x-axis).

The range of my x-axis is from 0 to 1000. Now here is my problem. I want to draw a line from specific points on the x-axis to the graph. For example, for points 40, 400, 950.

By using set(gca, 'XTick', [40 400 950]); I am able to mark these particular points. But I want to make it more visible by drawing straight vertical lines from these points.

Any help will be greatly appreciated. Thank you.

Upvotes: 2

Views: 5177

Answers (3)

yuk
yuk

Reputation: 19880

If you do this often I would recommend you a great submission from the FileExchange:

hline and vline

Just do:

vline([40 400 950])

Read the function documentation, if you want the line to have different properties than default.

Upvotes: 1

user1071136
user1071136

Reputation: 15725

Use plot with endpoints with the same x value and different y values. (and don't forget to use myaa to beautify the output).

x = 0:0.1:2*pi;
y = sin(x);
plot(x,y);
hold on;
plot([0.6 0.6], [-1 1], 'Color', [0.7 0.7 0.7], 'LineWidth', 2);
plot([3.6 3.6], [-1 1], 'Color', [0.7 0.7 0.7], 'LineWidth', 2);

enter image description here

Upvotes: 2

Pursuit
Pursuit

Reputation: 12345

I typically do this using something like this (is powers is a row vector).

powers = randn(1,1000)+40;
plot([1;1]*[40 400 950], [[0 0 0]; [powers([40 400 950])]],'k-')

Upvotes: 0

Related Questions