使用 Matlab 绘制矩阵条目图

发布于 2024-09-08 19:46:24 字数 120 浏览 4 评论 0原文

我有一个矩阵 A=magic(4) 并希望使用plot3(1:4,1:4,A,'ks') 绘制值。但这会将所有内容绘制在对角线上,而不是它们实际相对于矩阵中其他值的位置。我该怎么做?我确信这很简单,但我是 matlab 新手。

I've got a matrix A=magic(4) and wish to plot the values using plot3(1:4,1:4,A,'ks'). But that plots everything on the diagonal and not where they actually are relative to the other values in the matrix. How do I do that? I'm sure it's pretty easy but I'm new to matlab.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

不如归去 2024-09-15 19:46:24

您可以使用 MESHGRID 生成<绘制点的 code>X 和 Y 坐标:

[X,Y] = meshgrid(1:4);  %# X and Y are each 4-by-4 matrices, just like A
plot3(X,Y,A,'ks');      %# Make a 3-D plot of the points

您还可以使用函数 SURF,在这种情况下需要使用 MESHGRID 生成 XY 坐标是可选的:

surf(X,Y,A);      %# Use the 4-by-4 matrices from MESHGRID
surf(1:4,1:4,A);  %# Pass 1-by-4 vectors instead
surf(A);          %# Automatically uses 1:4 for each set of coordinates

You can use MESHGRID to generate matrices for the X and Y coordinates of the plotted points:

[X,Y] = meshgrid(1:4);  %# X and Y are each 4-by-4 matrices, just like A
plot3(X,Y,A,'ks');      %# Make a 3-D plot of the points

You could also plot a surface instead of a set of points using the function SURF, in which case the need to use MESHGRID to generate the X and Y coordinates is optional:

surf(X,Y,A);      %# Use the 4-by-4 matrices from MESHGRID
surf(1:4,1:4,A);  %# Pass 1-by-4 vectors instead
surf(A);          %# Automatically uses 1:4 for each set of coordinates
清风无影 2024-09-15 19:46:24

@gnovice 将是我的答案。

我要补充一点,有时简单的 imagesc 非常适合可视化矩阵:

imagesc(A)

@gnovice would be my answer.

I'll add that sometimes a simple imagesc is nice for visualizing a matrix:

imagesc(A)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文