在Matlab中适配hist3输出xx yy zz

Adapting hist3 in Matlab to output xx yy zz

我正在尝试调整 matlab 中的 hist3 函数,以便在生成直方图的同时输出绘制的变量,但我没有成功。谁能解释如何做到这一点?我尝试将 xx、yy、zz 声明为全局但它仍然不会将它们移动到工作区中。

我不会因为在论坛(也是 300 行长)上发布他们的代码(我认为是受版权保护的)而惹上 Matlab 的麻烦,但是您可以使用

open hist3

我在hist3的末尾添加了

if nargout > 0
nn = n; %this is the last line in the code

global x1 %I added these 
x1= xx;
global y1
y1 = yy;
global z1
z1 = zz;
end

根据 documentation

N = hist3(___) returns the number of elements in X that fall in each bin. This syntax does not create a histogram.

[N,C] = hist3(___) returns the positions of the bin centers in a 1-by-2 cell array of numeric vectors, and does not plot the histogram.

因此您可以通过这些语法获取双变量直方图计数和 bin 中心。

如果要绘制直方图并获取值,只需使用该函数两次:

hist3(yourData);
[N,C] = hist3(yourData);

现在,如果您还想要二维网格 (相当于您的 x1y1,您可以使用 meshgrid - documentations。使用 C{1}C{2} 作为 meshgrid 函数的输入。

我真的建议反对更改任何 MATLAB 的内置函数。