plot several X=const

조회 수: 2 (최근 30일)
Maxime
Maxime 2014년 9월 17일
댓글: Image Analyst 2014년 9월 17일
Hello,
I have a vector G (with 120 values).
I'd like to plot a vertical line for each value of this vector in a graph having an other curve. How can I do this?
thank you

답변 (1개)

Image Analyst
Image Analyst 2014년 9월 17일
Perhaps the stem() function?
g = rand(1, 10);
plot(g, 'ro-', 'LineWidth', 2);
hold on;
stem(g);
  댓글 수: 4
Image Analyst
Image Analyst 2014년 9월 17일
편집: Image Analyst 2014년 9월 17일
How about this:
Y = [2.5, 34, 65, -12]
G = [12.5, 5.789, 4.6102, 21.09]
plot(Y, 'ro-', 'LineWidth', 4);
grid on;
hold on;
stem(G, max(Y)*ones(1, length(G)), 'Marker', 'none', 'LineWidth', 4);
Note: Y and G don't have to have the same number of elements. ALso, you have not defined an X for the Y values so I'm just assuming X is the index number. For the "G" lines, I'm having them go just from 0 up to the max Y value since you gave no indication of where the lines start or stop.
Image Analyst
Image Analyst 2014년 9월 17일
Another option to go the full height of the graph is to use line() function:
Y = [2.5, 34, 65, -12]
G = [12.5, 5.789, 4.6102, 21.09]
plot(Y, 'ro-', 'LineWidth', 4);
grid on;
hold on;
yl = ylim();
for k = 1 : length(G)
x = G(k);
line([x, x], yl, 'Marker', 'none', 'LineWidth', 4);
end

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by