2010-07-05 19 views
0

我得到了一個矩陣A = magic(4),並希望使用plot3(1:4,1:4,A,'ks')繪製這些值。但是,它繪製了對角線上的所有東西,而不是它們實際上與矩陣中其他值相對的位置。我怎麼做?我確定這很容易,但我是matlab新手。使用Matlab製作矩陣條目的繪圖

+0

可能重複http://stackoverflow.com/questions/3169263/line-圖式與Matlab)。重複的用戶,接近重複的問題。 – Jonas 2010-07-05 04:23:01

回答

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

@gnovice將是我answe河

我會補充說,有時一個簡單的於imagesc是可視化矩陣不錯:

imagesc(A) 
[在Matlab線圖](的