How to plot multiple vertical lines at specific points on x axis?

조회 수: 1 (최근 30일)
Heya :)
Heya :) 2020년 3월 10일
댓글: Heya :) 2020년 3월 11일
I want to plot 0.8 at 0, 0.1 at 0.9 and 0.06 at -1.3. Here is what I am trying but I am onling getting a single line.
close all; clear all; clc;
x = -1.5:0.1:1.5;
y = zeros(1,31);
p1=plot([-1.3 1.3],[0 0.06]);
p2=plot([0.9 0.9],[0 0.1]);
p3=plot([0 0],[0 0.8]);
  댓글 수: 3
Ameer Hamza
Ameer Hamza 2020년 3월 10일
See the updated answer. Refer to this link for more details about formatting the line: https://www.mathworks.com/help/matlab/ref/plot.html#btzitot-Color

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

채택된 답변

Ameer Hamza
Ameer Hamza 2020년 3월 10일
편집: Ameer Hamza 2020년 3월 10일
You need to hold the axes to retain all plots
clc;
x = -1.5:0.1:1.5;
y = zeros(1,31);
ax = axes();
hold(ax);
p1=plot([-1.3 -1.3],[0 0.06],'r');
p2=plot([0.9 0.9],[0 0.1],'r');
p3=plot([0 0],[0 0.8],'r');

추가 답변 (1개)

Jakob B. Nielsen
Jakob B. Nielsen 2020년 3월 10일
By default, matlab replaces plots on an axes instead of adding. However, if you set hold on, it will add instead of replacing, like so:
close all; clear all; clc;
x = -1.5:0.1:1.5;
y = zeros(1,31);
p1=plot([-1.3 1.3],[0 0.06]);
hold on %the key!
p2=plot([0.9 0.9],[0 0.1]);
p3=plot([0 0],[0 0.8]);

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by