这个问题在这里已有答案:
如何在MATLAB中绘制没有黑边的曲面图? 4个答案为了给你一些上下文,我试图找出使用贝叶斯规则的研究问题的最优参数,我的问题与生成这些参数的先验概率分布有关。
假设我的两个参数是A和B.我知道A的先验分布看起来像Gamma分布,而我对B的分布看起来像归一化的高斯分布。 目标是在x和y轴上绘制这些分布,然后在z轴上绘制联合概率P(A,B)= P(A)* P(B)。 如果我能做到这一点,那么我可以确定A和B的哪些值最有可能解决我的问题。
所以我输入MATLAB
A = linspace(-50,50,1000); B = A; gamma = gampdf(A,5,5); norm = normpdf(B,0,5); [A B] = meshgrid(A,B); Z = gamma'*norm; surf(A,B,Z)当我这样做时,我得到了这个:
旋转这可能会给我一些我正在寻找的东西,但由于它全是黑色的,我无法确切地说出来。
有没有办法让它更容易区分并使网格工作? (我猜测网格不起作用,因为我的Z不是A和B的函数,而是伽玛和规范)。
任何帮助都会非常感激,因为我完全乐于接受其他方法。
This question already has an answer here:
How to draw a surface plot without black edges in MATLAB? 4 answersTo give you some context, I am trying to find out the optimal parameters for a research problem using Bayes rule, and my question here has to do with generating the prior probability distributions for these parameters.
Suppose that my two parameters are A and B. I know that the prior distribution for A is going to look like a Gamma distribution, and my distribution for B is going to look like a normalized Gaussian distribution. The goal is to plot these distributions on the x and y axes, and then plot the joint probability P(A,B) = P(A)*P(B) in the z-axis. If I can do that, then I can identify what values of A and B are most probable for my problem.
So I type in MATLAB
A = linspace(-50,50,1000); B = A; gamma = gampdf(A,5,5); norm = normpdf(B,0,5); [A B] = meshgrid(A,B); Z = gamma'*norm; surf(A,B,Z)When I do that, I get this:
Rotating this perhaps gives me something I'm looking for, but since it's all black, I can't really tell for sure.
Is there a way I can make it more easy to distinguish and have the mesh work? (I'm guessing the mesh didn't work because my Z is not a function of A and B, but rather of gamma and norm).
Any help would be much appreciated, since I'm completely open to alternative ways of doing this.
最满意答案
网格线是如此密集(每个维度有1000行),它只是显示为黑色。 使用set关闭网格线:
h = surf(A,B,Z); set(h,'linestyle','none');The grid lines are so dense (you have 1000 lines in each dimension) that it just appears black. Use set to turn off the grid lines:
h = surf(A,B,Z); set(h,'linestyle','none');更多推荐
发布评论