2017-08-29 68 views
2

我有一個3列的矩陣。前兩列是座標,第三列是重量或強度。使用2個座標列和權重列的密度圖

newmat = [ 27.37 -45.69 14.47 
      27.37 -45.68 18.58 
      27.37 -45.67 29.05 
      27.37 -45.66 51.7 
      ...  ...  ... ] 

我已經創建了一個散點圖:

scatterplot

不過,我想有類似的密度圖(如第二個圖here)。我曾嘗試使用hist3函數,如here,但我沒有弄清楚如何考慮第三列 - 權重。

+0

從圖片的鏈接:'out = accumarray([idxx,idxy],1);''你用'out = accumarray([idxx,idxy],weights)替換'' – Gelliant

+0

謝謝,但是它對我有何幫助? – Aviad

回答

0

你可以(使用功能sortrowsunique,並且accumarray)創建從數據newmat矩陣,並繪製它作爲image

newmat = sortrows(newmat, [1 2]); % Sort the first two columns in ascending order 
[x, ~, newmat(:, 1)] = unique(newmat(:, 1));  % Make numeric indices for column 1 
[y, ~, newmat(:, 2)] = unique(newmat(:, 2));  % Make numeric indices for column 2 
M = accumarray(newmat(:, 1:2), newmat(:, 3)).'; % Build the matrix 
imagesc(x, y, M); 

這裏是類似於您的格式一些示例數據:

[X, Y] = meshgrid(0:0.1:2, 3:0.1:5); 
Z = peaks(21); 
newmat = [X(:) Y(:) Z(:)]; 

下面是上面的代碼從數據產生的情節:

enter image description here

+0

非常感謝。這非常有用! – Aviad