drawvec.m

来自「用MATLAB程序解决高阶问题;通过20多个实例来说明线性代数在后续课和工程中的」· M 代码 · 共 35 行

M
35
字号
function [ handle ] = drawvec(v,color,s);
% ATLAST65中绘制向量的程序
% 《工程线性代数(MATLAB版)》引用
% 陈怀琛,高淑萍,杨威合编,电子工业出版社,2007年6月
% DRAWVEC(v,color,s) graphs the vector v using
% the color specified by the second input
% argument. If no second argument is specified
% the default color is red. The initial point 
% of the plot is the origin. An arrow is drawn 
% at the terminal point of the vector.
% Axis is set at [-s,s,-s,s]. If the third
% input argument s is not specified, its default
% value is 5.

% Modified by Emily Moore to return the handle of the
%   vector so we can set properties of Tag and Userdata.

if nargin==1
   color = 'r';
end
if nargin < 3
   s=5;
end
handle = plot([0,v(1)],[0,v(2)],color);
axis([-s,s,-s,s])
axis('square')
hold on
[m,n]=size(v);
if n==1  % Change to row vector
   v=v'; 
end
atip=tip(v,s);
fill(atip(1,:),atip(2,:),color)
hold off

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?