How can I plot two vectors starting from origin?

조회 수: 9 (최근 30일)
Chewy
Chewy 2015년 10월 21일
댓글: Star Strider 2015년 10월 22일
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
Star Strider
Star Strider 2015년 10월 22일
My pleasure!

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

추가 답변 (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