Add various horizontal lines to a plot Matlab 2016a

조회 수: 17 (최근 30일)
Ali Tawfik
Ali Tawfik 2020년 5월 5일
편집: Ameer Hamza 2020년 5월 5일
clear all;
clc;
close all
x=[33.5 44 55 69 106 143 123 49 -25];
y=[61.8 53 45 73 77 81 156 68 -18];
z=[-7.5 -5 -2.5 -2.5 0 2.5 2.5 5 7.5];
zz=z(1:3:end)
for i=1:3
zz_n(i)=zz(i)
end
for i=1:3
hold on
plot(x,z)
plot(x,zz_n(i)*ones(size(x)),':')
plot(y,z)
hold off
end
Hi all, I am using Matlab 2016a and trying to add various horizontal lines .. I aready added but I would like the lines to reach y-axis... any help.

채택된 답변

Ameer Hamza
Ameer Hamza 2020년 5월 5일
편집: Ameer Hamza 2020년 5월 5일
Sindar's answer works for R2018b and onward. For 2016a, you can use XLim as the x coordinates of line
clear all;
clc;
close all
x=[33.5 44 55 69 106 143 123 49 -25];
y=[61.8 53 45 73 77 81 156 68 -18];
z=[-7.5 -5 -2.5 -2.5 0 2.5 2.5 5 7.5];
zz=z(1:3:end)
for i=1:3
zz_n(i)=zz(i)
end
ax = axes();
hold on % just one hold on is enough
for i=1:3
plot(x,z)
plot(ax.XLim,zz_n(i)*ones(1,2),':')
plot(y,z)
end

추가 답변 (1개)

Sindar
Sindar 2020년 5월 5일

카테고리

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