2017-08-29 30 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

相关问题