フィルターのクリア

How can I plot two vectors starting from origin?

13 ビュー (過去 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 Center および File ExchangeVector Fields についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by