How can I plot two vectors starting from origin?

14 次查看(过去 30 天)
I wrote the following code to set the appearance of the axis and the figure:
search_width = 5;
figure2 = figure;
% Figure erstellen
axes2 = axes('Parent',figure2);
hold(axes2,'on');
% Axen erstellen
figure2.Name = sprintf('Vektoren in der Suchmaske - alpha = %g', alpha(1, 1));
figure2.NumberTitle = 'off';
% Titel des Fensters bearbeiten
axes2.XLim = [ (-(round((search_width/2)+1))) (round((search_width/2)+1))];
axes2.YLim = [ (-(round((search_width/2)+1))) (round((search_width/2)+1))];
axes2.XAxisLocation = 'origin';
axes2.YAxisLocation = 'origin';
% Achsen in den Mittelpunkt verschieben
% Vektoren
box(axes2,'on');
% Einstellungen zum Aussehen des Schaubildes
Now I want to plot two vectors.
a = [-3; -3]
b = [-3; 0]
a and b determines the end of the vectors. Starting-point shall be for both vectors the point [0, 0]. It would be nice if the vectors have the appearance of arrows. How can I manage this?
I use MATLAB R2015b.

采纳的回答

Star Strider
Star Strider 2015-10-21
Use the quiver function:
o = [0; 0];
a = [-3; -3];
ac = [a o];
auv = [o a];
b = [-3; 0];
bc = [b o];
buv = [o b];
figure(1)
quiver(ac(1,:), ac(2,:), auv(1,:), auv(2,:), 0)
hold on
quiver(bc(1,:), bc(2,:), buv(1,:), buv(2,:), 0)
hold off
axis([-5 1 -5 1])
  2 个评论
Chewy
Chewy 2015-10-22
Thanks a lot, that works. For everybody else who has the same problem, here´s the complete code:
edge_search_width = 5;
% Determination of search width
c_v_y = -1;
c_v_x = 3;
% Current-Vector
t_v = [0; -(edge_search_width-2)];
% Top-Vector, shows always to the top. x = 0, y = -edge_search_width.
% Calculations for quiver-command in the visualisation.
o = [0; 0];
c_v = [c_v_x; c_v_y];
ac = [c_v o];
auv = [o c_v];
bc = [t_v o];
buv = [o t_v];
%%Visualisation
figure2 = figure;
% create figure
axes2 = axes('Parent',figure2);
hold(axes2,'on');
% create axes
figure2.Name = 'vectors in searchmask';
figure2.NumberTitle = 'off';
% create title of the window
axes2.XLim = [ (-(round((edge_search_width/2)+1))) (round((edge_search_width/2)+1))];
axes2.YLim = [ (-(round((edge_search_width/2)+1))) (round((edge_search_width/2)+1))];
axes2.XAxisLocation = 'origin';
axes2.YAxisLocation = 'origin';
axes2.YDir = 'reverse';
% set axes to the origion
quiver(ac(1,:), ac(2,:), auv(1,:), auv(2,:), 0)
hold on
quiver(bc(1,:), bc(2,:), buv(1,:), buv(2,:), 0)
hold off
% plot vectors
box(axes2,'on');
% appearance of the figure

请先登录,再进行评论。

更多回答(1 个)

TastyPastry
TastyPastry 2015-10-21
编辑:TastyPastry 2015-10-21
Try the Da Vinci Draw Toolbox. The old arrow.m file doesn't work anymore.
There is a method using annotation() and another using quiver(). They quiver() method doesn't draw exact vectors to the endpoint.

类别

Help CenterFile Exchange 中查找有关 Vector Fields 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by