How to plot vertical lines for reference using vline?

92 visualizaciones (últimos 30 días)
Jonas Lara
Jonas Lara el 23 de Abr. de 2018
Editada: Pawel Jastrzebski el 24 de Abr. de 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 comentarios
Jonas Lara
Jonas Lara el 23 de Abr. de 2018
Editada: Jonas Lara el 23 de Abr. de 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.

Iniciar sesión para comentar.

Respuestas (1)

Pawel Jastrzebski
Pawel Jastrzebski el 24 de Abr. de 2018
Editada: Pawel Jastrzebski el 24 de Abr. de 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:

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by