散点图:高数组耗尽所有内存

scatter plot: tall arrays eating up all the memory

我正在研究 HDR 中的色调映射运算符。我的问题很简单。我想在 Matlab 2015Ra 上使用计算机规格核心 i5 20GB RAM 散点图大型阵列。只有散点图会占用整个内存(大约 20GB 的 92%)。我需要一些建议来绘制高数组。我知道 Matlab 2018 有 binscatter 函数,但我的版本较低。谢谢你。示例代码:

a=randn(21026304,1);
scatter(a,a); 

只有这段代码占用了所有内存。

您可以使用 histcounts2 自己创建一个类似 binscatter 的函数! Histcounts 将数据分箱到一个 NxN 数组中,然后您可以使用 imshow 对其进行可视化...这非常节省内存,因为无论输入大小如何,每个分箱只占用几个字节。

% Some (correlated) data
x = randn(1e6,1);
y = randn(1e6,1)+x;

% Count 32x32 bins
[N,ax,ay] = histcounts2(x,y,32);

% Some gradient
cmap = [linspace(1,0,16);
    linspace(1,0.3,16);
    linspace(1,0.5,16)].';

% Show the histogram
imshow(...
    N,[],...                        % N contains the counts, [] indicated range min-max
    'XData', ax, 'YData', ay, ...   % Axis ticks
    'InitialMagnification', 800,... % Enlarge 8x
    'ColorMap', cmap...             % The colormap
);

colorbar;       
axis on;
title('bin-counts');