使用Matlab制作矩阵条目图

时间:2010-07-05 04:12:43

标签: matlab matrix plot

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

2 个答案:

答案 0 :(得分:2)

您可以使用MESHGRID为绘制点的XY坐标生成矩阵:

[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

答案 1 :(得分:1)

@gnovice将是我的答案。

我要补充说,有时一个简单的图像c很适合可视化矩阵:

imagesc(A)