MATLAB箭头绘制 arrow3 函数与 quiver3 函数的实用教程

MATLAB 的 arrow3 函数可以方便地在 figure 窗口中绘制箭头,效率也还可以,这里简单介绍其基本使用方法以便读者参考。对于一般的使用场景而言arrow3的使用十分简单方便。但是,arrow3 是R13版本中的函数,后续已不再更新,对于需要绘制较多矢量箭头的场景,推荐使用 quiverquiver3 函数。对于采用箭头作为注释的场景,推荐使用 annotation 函数。

arrow3

基础绘图方式

arrow3 的基础绘图方式只需要指定箭头的起点(N x 3)、终点(N x 3)。如下:

figure;
arrow3([0 0 0],[1 1 1]);
grid on;

绘图效果如下:
figure1
如果给出多个起点、终点,便可以绘制多段箭头图形,注意起点、终点都是行向量。

figure;
arrow3([0 0 0;1 1 1],[1 1 1;2 1 1]);
grid on;

figure2
arrow3 可以用来绘制2D或3D的箭头。

进阶绘图方式

下面看看更复杂的绘图,使用 arrow3 可以指定箭头的颜色、尺寸、线形等等信息。
arrow3 完整的参数表为:

arrow3(P1,P2,S,W,H,IP,ALPHA,BETA)

其中最常用的 ‘S’ 参数可以指定颜色。

figure;
P1 = [0 0 0; 1 0 0; 1 0 1; 1 1 1; 0 1 0];
P2 = [P1(2:end,:); [0 1 1]];
S = 'b';
arrow3(P1,P2,S);
grid on;

figure3
颜色的设置代码可以参考官方帮助文档。颜色的设置可以十分灵活,例如可以通过前缀 ‘_’ 和 ‘^’ 改变颜色的深浅,深浅度由 BETA 参数指定;可以将颜色设置成随机的 ‘x’、按顺序的 ‘o’ 以及按幅度的 ‘|’;

figure;
P1 = [0 0 0; 1 0 0; 1 0 1; 1 1 1; 0 1 0];
P2 = [P1(2:end,:); [0 1 1]];
S = '_o';
arrow3(P1,P2,S);
grid on;

figure4

利用 S 参数,我们还可以指定箭头的其它特征,如线形和线的宽度,具体参考官方帮助文档。

figure;
S = 'x2.5';
arrow3(zeros(20,3),50*rand(20,3),S,2)
grid on;

figure41

为了效率,请尽量使用一种颜色。在这里有个疑问:箭头的颜色和线的颜色为什么有时候一样有时候不同?这个问题将在下一节讨论。

W 和 H 参数分别指定箭头的宽度和高度:

figure;
P1 = [0 0 0; 1 0 0; 1 0 1; 1 1 1; 0 1 0];
P2 = [P1(2:end,:); [0 1 1]];
S = '_o';
arrow3(P1,P2,S, 2.0, 6.0);
grid on;

figure5
IP 参数指定箭头起点的宽度:

figure;
P1 = [0 0 0; 1 0 0; 1 0 1; 1 1 1; 0 1 0];
P2 = [P1(2:end,:); [0 1 1]];
S = 'o';
arrow3(P1,P2,S, 2.0, 6.0, 2);
grid on;

figure6
ALPHA 参数用来指定箭头图形的透明度,取值[0,1]。BETA 参数用来指定颜色变深浅的成都,取值[0,1]。

figure;
P1 = [0 0 0; 1 0 0; 1 0 1; 1 1 1; 0 1 0];
P2 = [P1(2:end,:); [0 1 1]];
S = 'o';
arrow3(P1,P2,S, 2.0, 6.0, 2, 0.2);
grid on;

figure7
注意:对于不需要指定的参数,可以采用 ‘[]’ 跳过

颜色设定

颜色的设定是 arrow3 使用中较为复杂的环节。有三种方式可以指定箭头颜色:使用 ‘S’ 参数、使用全局变量 ‘ColorOrder’ 和设定 ‘gca’。这里仅介绍前两种方式,第3种请参考官方帮助文档。

S 参数的使用

事实上,arrow3 中 ‘S’ 参数若仅包含对箭头部分的颜色设定,而线部分则取决于MATLAB中的绘图颜色计数,如:

figure;
theta=[0:pi/22:pi/2]';
arrow3(zeros(12,2),[cos(theta),sin(theta)],'c',1.5,[],[],[],0.5);
hold on;
arrow3(zeros(12,2),[cos(theta+pi/2),sin(theta+pi/2)],'j',1.5,[],[],[],0.5)
arrow3(zeros(12,2),[cos(theta+pi),sin(theta+pi)],'z',1.5,[],[],[],0.5)
axis([-Inf,Inf, -Inf, Inf]);
grid on;

figure8
三个 ‘S’ 值指定了箭头的颜色,而线的三种颜色事实上是因为绘制了三次,采用了MATLAB绘图的颜色计数,这个计数顺序实际上等同于将 ‘S’ 值设定为 ‘o’ 时的顺序。我们同样可以在一次绘图中让线的颜色也按顺序出现,只需在 ‘S’ 参数中加入 ‘*’ ,如:

figure;
theta=[0:pi/22:pi/2]';
arrow3(zeros(12,2),[cos(theta),sin(theta)],'c*',1.5,[],[],[],0.5);
hold on;
axis([-Inf,Inf, -Inf, Inf]);
grid on;

figure9
如果将 ‘S’ 参数设定为按顺序 ‘o’ 或者随机 ‘x’,那么箭头部分与线部分的颜色会被同时影响,如:

figure;
theta=[0:pi/22:pi/2]';
arrow3(zeros(12,2),[cos(theta),sin(theta)],'o',1.5,[],[],[],0.5);
hold on;
arrow3(zeros(12,2),[cos(theta+pi/2),sin(theta+pi/2)],'j',1.5,[],[],[],0.5)
arrow3(zeros(12,2),[cos(theta+pi),sin(theta+pi)],'z',1.5,[],[],[],0.5)
axis([-Inf,Inf, -Inf, Inf]);
grid on;

figure10
我们采用 ‘S’ 参数并不能直接控制线部分的颜色。

全局变量 ColorOrder

另外一种设置颜色的方式是重定义 ‘ColorOrder’ 全局变量。此时需要将 ‘S’ 参数设定为 ‘o’。全局变量 ‘ColorOrder’ 的默认值是 ‘bersvpd’。我们可以在其中加入 ‘_’ 或 ‘^’ 前缀来改变颜色的深浅。例如:

figure;
global ColorOrder, ColorOrder='^ss_s';
theta=[0:pi/22:pi/2]';
arrow3(zeros(12,2),[cos(theta),sin(theta)],'o',1.5,[],[],[],0.5);
hold on;
arrow3(zeros(12,2),[cos(theta+pi/2),sin(theta+pi/2)],'k',1.5,[],[],[],0.5)
axis([-Inf,Inf, -Inf, Inf]);
grid on;

figure11
可以看出,设置 ‘S’ 参数为 ‘o’ 同时影响了线部分的颜色计数。同上,我们只要指定线形标志 ‘*’ 即可让线部分颜色按 ‘ColorOrder’ 顺序变化:

figure;
global ColorOrder, ColorOrder='^ss_s_zz^z';
theta=[0:pi/22:pi/2]';
arrow3(zeros(12,2),[cos(theta),sin(theta)],'o',1.5,[],[],[],0.5);
hold on;
arrow3(zeros(12,2),[cos(theta+pi/2),sin(theta+pi/2)],'*k',1.5,[],[],[],0.5)
axis([-Inf,Inf, -Inf, Inf]);
grid on;

figure12

arrow3 官方帮助文档

arrow3 (R13)
arrow3(P1,P2) draws lines from P1 to P2 with directional arrowheads. P1 and P2 are either nx2 or nx3 matrices. Each row of P1 is an initial point, and each row of P2 is a terminal point.

arrow3(P1,P2,S,W,H,IP,ALPHA,BETA) can be used to specify properties of the line, initial point marker, and arrowhead. S is a character string made with one element from any or all of the following 3 columns:

  Color Switches      LineStyle            LineWidth
  ------------------  -------------------  --------------------
  k  blacK (default)  -  solid (default)   0.5 points (default)
  y  Yellow           :  dotted            0   no lines
  m  Magenta          -. dashdot           /   LineWidthOrder
  c  Cyan             -- dashed
  r  Red              *  LineStyleOrder            _______ __  
  g  Green                                       ^        |    
  b  Blue                                       / \       |    
  w  White                        Arrowhead    /   \   Height  
  a  Asparagus                                /     \     |    
  d  Dark gray                               /       \    |    
  e  Evergreen                              /___   ___\ __|__  
  f  Firebrick                             |    | |    |       
  h  Hot pink                              |-- Width --|       
  i  Indigo                                |    | |    |       
  j  Jade                                       | |            
  l  Light gray                                 | |            
  n  Nutbrown                                   | |            
  p  Pear                                       | |            
  q  kumQuat                      Line       -->| |<--LineWidth
  s  Sky blue                                   | |            
  t  Tawny                                      | |            
  u  bUrgundy                                   | |            
  v  Violet                                     | |            
  z  aZure                                      | |            
  x  random                       Initial      /   \           
  o  colorOrder                   Point    -->(     )<--IP     
  |  magnitude                    Marker       \_ _/           

  -------------------------------------------------------------
                       Color Equivalencies
  -------------------------------------------------------------
  ColorOrder     Arrow3         |     Simulink       Arrow3
  ----------     ----------     |     ----------     ----------
  Color1         Blue           |     LightBlue      aZure
  Color2         Evergreen      |     DarkGreen      Asparagus
  Color3         Red            |     Orange         kumQuat
  Color4         Sky blue       |     Gray           Light gray
  Color5         Violet         |
  Color6         Pear           |
  Color7         Dark gray      |
  -------------------------------------------------------------

The components of S may be specified in any order. Invalid characters in S will be ignored and replaced by default settings.

Prefixing the color code with ‘_’ produces a darker shade, e.g. ‘_t’ is dark tawny; prefixing the color code with ‘^’ produces a
lighter shade, e.g. ‘^q’ is light kumquat. The relative brightness of light and dark color shades is controlled by the scalar parameter BETA. Color code prefixes do not affect black (k), white (w), or the special color switches (xo|).

ColorOrder may be achieved in two fashions: The user may either set the ColorOrder property (using RGB triples) or define the
global variable ColorOrder (using a string of valid color codes). If the color switch is specified with ‘o’, and the global variable ColorOrder is a string of color codes (color switches less ‘xo|’, optionally prefixed with ‘_’ or ‘^’), then the ColorOrder property will be set to the sequence of colors indicated by the ColorOrder variable. The color sequence ‘bersvpd’ matches the default ColorOrder property. If the color switch is specified with ‘o’, and the global variable ColorOrder is empty or invalid, then the current ColorOrder property will be used. Note that the ColorOrder variable takes precedence over the ColorOrder property.

The magnitude color switch is used to visualize vector magnitudes in conjunction with a colorbar. If the color switch is specified
with ‘|’, colors are linearly interpolated from the current ColorMap according to the length of the associated line. This option sets
CLim to [MinM,MaxM], where MinM and MaxM are the minimum and maximum magnitudes, respectively.

The current LineStyleOrder property will be used if LineStyle is specified with ‘*’. MATLAB cycles through the line styles defined
by the LineStyleOrder property only after using all colors defined by the ColorOrder property. If however, the global variable
LineWidthOrder is defined, and LineWidth is specified with ‘/’, then each line will be drawn with sequential color, linestyle, and linewidth.

W (default = 1) is a vector of arrowhead widths; use W = 0 for no arrowheads. H (default = 3W) is a vector of arrowhead heights. If vector IP is neither empty nor negative, initial point markers will be plotted with diameter IP; for default diameter W, use IP = 0. The units of W, H and IP are 1/72 of the PlotBox diagonal.

ALPHA (default = 1) is a vector of FaceAlpha values ranging between 0 (clear) and 1 (opaque). FaceAlpha is a surface arrowhead and initial point marker) property and does not affect lines. FaceAlpha is not supported for 2D rendering.

BETA (default = 0.4) is a scalar that controls the relative brightness of light and dark color shades, ranging between 0 (no contrast) and 1 (maximum contrast).

Plotting lines with a single color, linestyle, and linewidth is faster than plotting lines with multiple colors and/or linestyles. Plotting lines with multiple linewidths is slower still. arrow3 chooses renderers that produce the best screen images; exported or printed plots may benefit from different choices.

arrow3(P1,P2,S,W,H,‘cone’,…) will plot cones with bases centered on P1 in the direction given by P2. In this instance, P2 is interpreted as a direction vector instead of a terminal point. Neither initial point markers nor lines are plotted with the ‘cone’ option.

HN = arrow3(P1,P2,…) returns a vector of handles to line and surface objects created by arrow3.

arrow3 COLORS will plot a table of named colors with default brightness. arrow3(‘colors’,BETA) will plot a table of named colors with brightness BETA.

arrow3 attempts to preserve the appearance of existing axes. In particular, arrow3 will not change XYZLim, View, or CameraViewAngle. arrow3 does not, however, support stretch-to-fill scaling. AXIS NORMAL will restore the current axis box to full size and remove any restrictions on the scaling of units, but will likely result in distorted arrowheads and initial point markers. See (arrow3_messes_up_my_plots.html).

If a particular aspect ratio or variable limit is required, use DASPECT, PBASPECT, AXIS, or XYZLIM commands before calling arrow3. Changing limits or aspect ratios after calling arrow3 may alter the appearance of arrowheads and initial point markers. arrow3 sets XYZCLimMode to manual for all plots, sets DataAspectRatioMode to manual for linear plots, and sets PlotBoxAspectRatioMode to manual for log plots and 3D plots. CameraViewAngleMode is also set to manual for 3D plots.

arrow3 UPDATE will restore the appearance of arrowheads and initial point markers that have become corrupted by changes to limits or aspect ratios. arrow3(‘update’,SF) will redraw initial point markers and arrowheads with scale factor SF. If SF has one element, SF scales W, H and IP. If SF has two elements, SF(1) scales W and IP, and SF(2) scales H. If SF has three elements, SF(1) scales W, SF(2) scales H, and SF(3) scales IP. All sizes are relative to the current PlotBox diagonal.

arrow3 UPDATE COLORS will update the magnitude coloring of arrowheads, initial point markers, and lines to conform to the current ColorMap.

HN = arrow3(‘update’,…) returns a vector of handles to updated objects.

EXAMPLES:

  % 2D vectors
  arrow3([0 0],[1 3])
  arrow3([0 0],[1 2],'-.e')
  arrow3([0 0],[10 10],'--x2',1)
  arrow3(zeros(10,2),50*rand(10,2),'x',1,3)
  arrow3(zeros(10,2),[10*rand(10,1),500*rand(10,1)],'u')
  arrow3(10*rand(10,2),50*rand(10,2),'x',1,[],1)

  % 3D vectors
  arrow3([0 0 0],[1 1 1])
  arrow3(zeros(20,3),50*rand(20,3),'--x1.5',2)
  arrow3(zeros(100,3),50*rand(100,3),'x',1,3)
  arrow3(zeros(10,3),[10*rand(10,1),500*rand(10,1),50*rand(10,1)],'a')
  arrow3(10*rand(10,3),50*rand(10,3),'x',[],[],0)

  % Cone plot
  t=(pi/8:pi/8:2*pi)'; p1=[cos(t) sin(t) t]; p2=repmat([0 0 1],16,1);
  arrow3(p1,p2,'x',2,4,'cone'), hold on
  plot3(p1(:,1),p1(:,2),p1(:,3)), hold off
  pause % change cone size
  arrow3('update',[1,2])

  % Just for fun
  arrow3(zeros(100,3),50*rand(100,3),'x',8,4,[],0.95)
  light('position',[-10 -10 -10],'style','local')
  light('position',[60,60,60]), lighting gouraud

  % ColorOrder variable, color code prefixes, and Beta
  global ColorOrder, ColorOrder='^ui^e_hq^v';
  theta=[0:pi/22:pi/2]';
  arrow3(zeros(12,2),[cos(theta),sin(theta)],'1.5o',1.5,[],[],[],0.5)

  % ColorOrder property, LineStyleOrder, and LineWidthOrder
  global ColorOrder, ColorOrder=[];
  set(gca,'ColorOrder',[1,0,0;0,0,1;0.25,0.75,0.25;0,0,0])
  set(gca,'LineStyleOrder',{'-','--','-.',':'})
  global LineWidthOrder, LineWidthOrder=[1,2,4,8];
  w=[1,2,3,4]; h=[4,6,4,2];
  arrow3(zeros(4,2),[10*rand(4,1),500*rand(4,1)],'o*/',w,h,0)

  % Magnitude coloring
  colormap spring
  arrow3(20*randn(20,3),50*randn(20,3),'|',[],[],0)
  set(gca,'color',0.7*[1,1,1])
  set(gcf,'color',0.5*[1,1,1]), grid on, colorbar
  pause % change the ColorMap and update colors
  colormap hot
  arrow3('update','colors')

  % LogLog plot
  set(gca,'xscale','log','yscale','log');
  axis([1e2,1e8,1e-2,1e-1]); hold on
  p1=repmat([1e3,2e-2],15,1);
  q1=[1e7,1e6,1e5,1e4,1e3,1e7,1e7,1e7,1e7,1e7,1e7,1e6,1e5,1e4,1e3];
  q2=1e-2*[9,9,9,9,9,7,5,4,3,2,1,1,1,1,1]; p2=[q1',q2'];
  global ColorOrder, ColorOrder=[];
  set(gca,'ColorOrder',rand(15,3))
  arrow3(p1,p2,'o'), grid on, hold off

  % SemiLogX plot
  set(gca,'xscale','log','yscale','linear');
  axis([1e2,1e8,1e-2,1e-1]); hold on
  p1=repmat([1e3,0.05],15,1);
  q1=[1e7,1e6,1e5,1e4,1e3,1e7,1e7,1e7,1e7,1e7,1e7,1e6,1e5,1e4,1e3];
  q2=1e-2*[9,9,9,9,9,7,5,4,3,2,1,1,1,1,1]; p2=[q1',q2'];
  arrow3(p1,p2,'x'), grid on, hold off

  % SemiLogY plot
  set(gca,'xscale','linear','yscale','log');
  axis([2,8,1e-2,1e-1]); hold on
  p1=repmat([3,2e-2],17,1);
  q1=[7,6,5,4,3,7,7,7,7,7,7,7,7,6,5,4,3];
  q2=1e-2*[9,9,9,9,9,8,7,6,5,4,3,2,1,1,1,1,1]; p2=[q1',q2'];
  set(gca,'LineStyleOrder',{'-','--','-.',':'})
  arrow3(p1,p2,'*',1,[],0), grid on, hold off

  % Color tables
  arrow3('colors')           % default color table
  arrow3('colors',0.3)       % low contrast color table
  arrow3('colors',0.5)       % high contrast color table

  % Update initial point markers and arrowheads
  % relative to the current PlotBox diagonal
  arrow3('update')           % redraw same size
  arrow3('update',2)         % redraw double size
  arrow3('update',0.5)       % redraw half size
  arrow3('update',[0.5,2,1]) % redraw W half size,
                             %        H double size, and
                             %        IP same size

See also (arrow3_examples.html), (arrow3_messes_up_my_plots.html).

quiver3

quiver3 通常用来绘制矢量图中的箭头。quiver3 的用法与 plot、scatter等非常相似,参数指定完全可以参考。

基础绘图方式

quiver3 函数的基本格式如下:

quiver3(X,Y,Z,U,V,W)

‘X’, ‘Y’, ‘Z’ 分别指定箭头起点,即位置;‘U’, ‘V’, ‘W’ 分别指定箭头的长度和方向,即速度。

figure;
quiver3(0,0,0,1,1,1);
axis([-Inf, Inf, -Inf, Inf]);
axis equal; grid on;

figure13
可以看出,quiver3 所绘制的箭头十分简洁,与 arrow3 的形式完全不同。其中颜色、线宽等参数可以采用plot的方式指定。

figure;
quiver3(0,0,0,1,1,1,'Color',[1.0,0.0,0.0],'LineWidth',2.0);
axis([-Inf, Inf, -Inf, Inf]);
axis equal; grid on;

figure14
我们也可以通过循环来分别制定颜色:
quivers

注意,此时我们无法分别指定箭头的颜色和线的颜色,二者只能相同。箭头的大小与线的长度有关,会自动根据线调整,不可精确指定。我们可以通过 ‘W’ 之后的一个输入参数 'scale‘ 来相对地调整箭头大小,将其设定为 ‘0’ 或者 ’ ‘off’ ’ 即可取消自动调整。也可以修改 'AutoScale’ 属性和’AutoScaleFactor‘属性来进行调整。

进阶绘图方式

这里仅介绍线形调整,用法如下:

quiver3(___,LineSpec)

通过指定 'LinSpec’ 参数来调整线形,线形标志与 arrow3 的多数相同。

figure;
quiver3(0,0,0,1,1,1, '--r','LineWidth',1.0);
axis([-Inf, Inf, -Inf, Inf]);
axis equal; grid on;

figure15
指定方式与 plot 基本相同,其余标志请参考官方帮助文档。

  • 11
    点赞
  • 63
    收藏
    觉得还不错? 一键收藏
  • 7
    评论
### 回答1: Matlab是一款常用的数学计算软件,在绘制函数图像时,经常需要指定坐标轴和绘制箭头以表示方向。下面介绍如何在Matlab绘制箭头坐标轴。 Matlab提供了一个Quiver函数,可以用来绘制带有箭头的向量场。我们可以利用该函数绘制箭头坐标轴。 首先,要生成一些数据点来表示箭头的位置和方向。可以使用meshgrid函数来生成一组网格点坐标。例如,下面的代码生成了一个包含20个点的矩阵X和Y。 [X, Y] = meshgrid(linspace(-1,1,20), linspace(-1,1,20)); 接下来,定义一个表示水平方向的向量U和表示垂直方向的向量V。这里使用了sin和cos函数来生成一个类似于“十字”形状的向量场。 U = cos(X) + sin(Y); V = sin(X) - cos(Y); 最后,调用quiver函数绘制向量场,并用axis函数来指定坐标轴范围。 quiver(X,Y,U,V); axis([-1.2 1.2 -1.2 1.2]); 绘制出来的图像会在上下左右四个方向上增加箭头来表示坐标轴方向。 除了使用quiver函数绘制向量场外,Matlab还提供了多种绘制箭头的方式,比如arrow函数、annotation函数等。不同的绘制方式适用于不同的场景和需求,具体选择要根据实际情况来决定。 ### 回答2: 在Matlab绘制函数图像可以使用plot函数,也可以使用fplot函数。当我们需要在绘图中添加箭头或坐标轴时,可以使用quiver函数。 Quiver函数的基本用法是:quiver(x,y,u,v)。其中x和y表示箭头的起点坐标,u和v表示箭头的长度和方向,可以理解为横向和纵向的分量。除此之外,quiver函数还可以添加一些参数,比如添加颜色、箭头的宽度等。 绘制坐标轴可以使用axis函数或gca函数。axis函数可以设置坐标轴的取值范围,gca函数可以获取当前的坐标轴对象,通过修改其属性实现更加精细的定制。 举个例子,如果我们需要绘制一个sin函数及其一阶导数的曲线,可以按照以下步骤操作: 1. 定义x轴的取值范围:x = linspace(0, 2*pi, 100); 2. 计算函数值:y = sin(x); dy = cos(x); 3. 绘制函数图像:plot(x, y); hold on; plot(x, dy); 4. 添加箭头:quiver(x, y, ones(size(x)), dy, 0.5); 5. 设置坐标轴:axis([0 2*pi -1.5 1.5]); gca().YAxisLocation = 'origin'; 在上述代码中,quiver函数中的第四个参数表示箭头的长度,这里设置为0.5。最后一行代码将Y轴的位置设置为原点。 以上就是使用Matlab绘制函数图像并添加箭头坐标轴的基本方法。需要注意的是,在实际操作中需要根据具体的情况调整参数和图像的样式。 ### 回答3: Matlab是一种常用的工具软件,可以用来进行数学计算、科学绘图等等。在函数图像绘制方面,Matlab提供了非常丰富的功能,可以方便地实现各种绘图需求。 其中,绘制箭头和坐标轴也是Matlab的一项常见功能。在绘制函数图像时,我们常常需要标注出坐标轴和箭头,以便读者更好地理解函数的变化趋势和特征。 在Matlab中,绘制坐标轴可以使用axes函数和axis函数来实现,它们可以设置坐标轴的范围、刻度、标签等等。而绘制箭头则可以使用quiver函数来实现,quiver函数可以根据坐标轴上的向量大小和方向绘制对应的箭头。 具体地说,我们可以使用如下代码来实现在Matlab绘制带有箭头的坐标轴: ```matlab % 设置坐标轴范围和刻度 axis([-5 5 -5 5]) xticks([-5:1:5]) yticks([-5:1:5]) % 绘制x轴和y轴 axes('Position',[0.1 0.1 0.8 0.8]) plot([-5 5],[0 0],'k','LineWidth',1.2) % x轴 hold on plot([0 0],[-5 5],'k','LineWidth',1.2) % y轴 % 绘制箭头 quiver(4,0,1,0,'LineWidth',1.5,'MaxHeadSize',0.5) % x轴箭头 quiver(0,4,0,1,'LineWidth',1.5,'MaxHeadSize',0.5) % y轴箭头 % 设置坐标轴标签 xlabel('x') ylabel('y') ``` 上述代码中,我们首先在坐标轴上设置了范围和刻度,并使用plot函数分别绘制x轴和y轴。然后,在箭头绘制部分,我们使用了quiver函数绘制箭头,并设置了箭头宽度、最大头部尺寸等属性。 最后,我们使用xlabel和ylabel函数来设置坐标轴的标签。这样,在Matlab中就可以方便地绘制带有箭头的坐标轴了。
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值