How to plot vertical lines for reference using vline?

89 Ansichten (letzte 30 Tage)
Jonas Lara
Jonas Lara am 23 Apr. 2018
Bearbeitet: Pawel Jastrzebski am 24 Apr. 2018
Im using vline and hline unsuccesfully. It seems that doesn't work when i need it. Example:
if true
x = -10:.2:10;
y = sin(x)+2;
plot(x, y)
vline(0, 'k')
hline(0, 'k')
grid minor
axis([-5 5 -5 5])
hold on
y = sin(x) - 2;
plot(x,y)
end
  4 Kommentare
Jonas Lara
Jonas Lara am 23 Apr. 2018
Bearbeitet: Jonas Lara am 23 Apr. 2018
wow, thank you. It is more than i need, i guess it will work perfectly. Let me try it and come back with a feedback.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Pawel Jastrzebski
Pawel Jastrzebski am 24 Apr. 2018
Bearbeitet: Pawel Jastrzebski am 24 Apr. 2018
I've moved my comment to the answer so the question can be closed. I've also tried to copy your example to show you what I think you're trying to achieve:
% DATA
x = -10:.2:10;
y0 = sin(x);
y1 = y0+2;
y2 = y0-2;
% PLOTTING
f(1) = figure; % create a new figure window
ax(1)= gca(); % handle to the current's figure axis
% Handles to the plot lines.
% Alternatively you could write it as:
% p(1:3) = plot(x, [y0; y1; y2]);
p(1) = plot(x,y0);
hold on
p(2) = plot(x,y1);
p(3) = plot(x,y2);
% USE THE HANDLES TO CHANGE THE PROPERTIES OF THE AXES AND LINES
set(p(1),...
'LineWidth', 0.5,...
'LineStyle', '--');
set([p(2) p(3)],...
'LineWidth', 2,...
'LineStyle', '-');
set(ax(1),...
'XAxisLocation','origin',...
'YAxisLocation','origin',...
'XLim', [-8 6],...
'YLim', [-4 2],...
'XMinorGrid','on',...
'YMinorGrid','on');
set(ax(1).Title,...
'String','Sine plots',...
'Color',[1 0 0],...
'FontSize',14);
set(ax(1).XLabel,...
'String', 'X-label');
set(ax(1).YLabel,...
'String', 'Y-label');
set([ax(1).XLabel ax(1).YLabel],...
'Color',[0 0 1],...
'FontSize',12);
Output:
All of the properties that you can change are listed in the following:

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by