Main Content

本页翻译不是最新的。点击此处可查看最新英文版本。

compass

从原点发射出的箭头

  • Circular grid with arrows emanating from the origin

说明

示例

compass(U,V) 绘制从点 (0, 0) 发射出的箭头。使用笛卡尔坐标 UV 指定箭头方向,其中 U 表示 x 坐标,V 表示 y 坐标。箭头数量与 U 中的元素数相匹配。

compass 函数在圆形网格上绘制箭头,并在 Axes 对象中添加 theta 轴和 r 轴刻度标签。因此,您指定的坐标与绘图上显示的标签不匹配。

示例

compass(Z) 使用由 Z 指定的复数值的实部和虚部绘制箭头,实部表示 x 坐标,虚部表示 y 坐标。此语法等效于 compass(real(Z),imag(Z))

示例

compass(___,LineSpec) 设置箭头的线型、标记符号和颜色。

示例

compass(ax,___) 在指定坐标区(而不是当前坐标区)中绘制箭头。

示例

c = compass(___) 返回由 Line 对象组成的向量。此语法对于控制箭头的外观很有用。

示例

全部折叠

通过指定每个箭头的笛卡尔坐标创建罗盘图。

u = [5 3 -4 -3 5];
v = [1 5 3 -2 -6];
compass(u,v)

通过先将极坐标转换为笛卡尔坐标的方法来使用极坐标创建罗盘图。

要完成此操作,请使用极坐标指定数据。使用 pol2cart 函数将它们转换为笛卡尔坐标。然后,创建绘图。

th = linspace(pi/4,2*pi,10);
r = linspace(5,20,10);
[u,v] = pol2cart(th,r);
compass(u,v)

请注意,theta 轴和 r 轴刻度标签对应于极坐标。

以等间距对正弦波进行采样。然后,计算正弦波的 10 点离散傅里叶变换。结果是一个由复数值组成的向量。

t = linspace(0,8*pi,100);
y = sin(2*t) + 2*sin(t+pi/2);
f = fft(y,10);

使用罗盘图显示复数值。实部确定每个箭头的 x 坐标,虚部确定 y 坐标。

compass(f)

创建一个带红色箭头的罗盘图。

u = [5 3 -4 -3 5];
v = [1 5 3 -2 -6];
compass(u,v,'r')

通过为单个箭头赋予变量,然后设置其属性来指定该箭头的线宽和颜色。为此,首先创建一个罗盘图并返回一个 Line 对象数组。

u = [3 5 -4 -3 5];
v = [5 1 3 -2 -6];
c = compass(u,v);

为第一个箭头赋予一个变量。第一个箭头对应于 uv 的第一组元素。然后,更改线宽和颜色。

c1 = c(1);
c1.LineWidth = 2;
c1.Color = 'r';

使用 view 函数旋转罗盘图,使 0 度指向上方。

要完成此操作,使用极坐标创建一个罗盘图。使用 pol2cart 函数将极坐标转换为笛卡尔坐标,然后绘制转换后的坐标。

th = linspace(0,3*pi/2,10);
r = linspace(5,20,10);
[u,v] = pol2cart(th,r);
compass(u,v)

请注意,0 度指向右侧。通过调用 view 并将第一个参数指定为 -90,将 theta 轴逆时针旋转 90 度。通过将第二个参数指定为 90 来保持二维视图。

view(-90,90)

请注意,0 度现在指向上方。

从 R2019b 开始,您可以使用 tiledlayoutnexttile 函数显示分块图。调用 tiledlayout 函数以创建 1×2 分块图布局。调用 nexttile 函数创建一个坐标区对象,并将该对象返回为 ax1。通过将 ax1 传递给 compass 函数来创建左图。通过将坐标区传递给 title 函数为绘图添加标题。重复上述过程以创建右图。

u = [7 5 -2 -5 8];
tiledlayout(1,2)

% Left plot
ax1 = nexttile;
v1 = [3 7 5 -4 -6];
compass(ax1,u,v1)
title(ax1,'Left Plot')

% Right plot
ax2 = nexttile;
v2 = [-3 -4 -5 6 6];
compass(ax2,u,v2)
title(ax2,'Right Plot')

输入参数

全部折叠

x 坐标,指定为标量、向量或矩阵。指定笛卡尔值。要将数据从极坐标转换为笛卡尔坐标,请使用 pol2cart

U 的大小必须与 V 的大小匹配。

y 坐标,指定为标量、向量或矩阵。指定笛卡尔值。要将数据从极坐标转换为笛卡尔坐标,请使用 pol2cart

V 的大小必须与 U 的大小匹配。

复数值,指定为标量、向量或矩阵。Z 的实部表示箭头的 x 坐标,虚部表示 y 坐标。

线型、标记和颜色,指定为包含符号的字符串标量或字符向量。符号可以按任意顺序显示。您不需要同时指定所有三个特征(线型、标记和颜色)。例如,如果忽略线型,只指定标记,则绘图只显示标记,不显示线条。

示例: "--or" 是带有圆形标记的红色虚线。

线型描述表示的线条
"-"实线

Sample of solid line

"--"虚线

Sample of dashed line

":"点线

Sample of dotted line

"-."点划线

Sample of dash-dotted line, with alternating dashes and dots

标记描述生成的标记
"o"圆圈

Sample of circle marker

"+"加号

Sample of plus sign marker

"*"星号

Sample of asterisk marker

"."

Sample of point marker

"x"叉号

Sample of cross marker

"_"水平线条

Sample of horizontal line marker

"|"垂直线条

Sample of vertical line marker

"square"方形

Sample of square marker

"diamond"菱形

Sample of diamond marker

"^"上三角

Sample of upward-pointing triangle marker

"v"下三角

Sample of downward-pointing triangle marker

">"右三角

Sample of right-pointing triangle marker

"<"左三角

Sample of left-pointing triangle marker

"pentagram"五角形

Sample of pentagram marker

"hexagram"六角形

Sample of hexagram marker

颜色名称短名称RGB 三元组外观
"red""r"[1 0 0]

Sample of the color red

"green""g"[0 1 0]

Sample of the color green

"blue""b"[0 0 1]

Sample of the color blue

"cyan" "c"[0 1 1]

Sample of the color cyan

"magenta""m"[1 0 1]

Sample of the color magenta

"yellow""y"[1 1 0]

Sample of the color yellow

"black""k"[0 0 0]

Sample of the color black

"white""w"[1 1 1]

Sample of the color white

目标坐标区,指定为 Axes 对象。

扩展功能

版本历史记录

在 R2006a 之前推出

另请参阅

函数

属性