简体   繁体   English

查找histfit和直线之间的交点-MATLAB

[英]Find point of intersection between histfit and line - MATLAB

How can I find the exact y-coordinate of the red gaussian at x = 0.5 without using Data Cursor? 如何在不使用数据游标的情况下找到x = 0.5时红色高斯的精确y坐标?

<code> histfit </ code>图

I want the blue line to end when it touches the gaussian. 我希望蓝线在接触高斯时结束。 But I need to find the point of intersection between the gaussian of the histfit shown in red, and the blue line at 0.5. 但是我需要找到以红色显示的histfit的高斯与以histfit表示的蓝线之间的交点。 I can access the data points of the histfit plot as follows: 我可以按以下方式访问histfit图的数据点:

C = get(get(gca, 'Children'), 'YData');
C{1,1}

line([0.5 0.5],[0 max(C{1,1})],'Color','b');

However, the data points of the gaussian don't relate to this axes. 但是,高斯的数据点与此轴无关。 Meaning, x-axis of C{1,1} is from 1 - 100 and not from 0.1 to 0.9. 意思是, C{1,1} x轴是1-100,而不是0.1到0.9。

Whats the easiest way to find the y-coordinate of the gaussian at 0.5 so that I can replace max(C{1,1}) by that? 找到0.5的高斯y坐标的最简单方法是什么,这样我就可以用它代替max(C{1,1})

Getting XData as well should give you the right x-values: 同样获得XData应该会为您提供正确的x值:

C = get(get(gca, 'Children'), 'XData');

Alternatively, the values of YData should be at regular intervals, even if not on the correct scale (since it originated from hist ), so you could probably find the y-value corresponding to x=0.5 in the plot. 另外, YData的值YData应以规则的间隔,即使不是正确的比例(因为它起源于hist )也是如此,因此您可能会在图中找到对应于x = 0.5的y值。

The point x=0.5 between 0.1 and 0.85 (approximately, from the plot) scales to the point x=53.33 between 1 and 100. If the y-value at x=53 isn't accurate enough for plotting, you can just interpolate the value between 53 and 54 and that should be enough. 在0.1和0.85之间的点x = 0.5(大约从该图开始)缩放到在1和100之间的点x = 53.33。如果x = 53处的y值不够精确,则可以对图进行插值值介于53到54之间,就足够了。

Here is some code to that should do the job: 这是应该执行的一些代码:

XPlotRange = [0.1 0.85];
XDataRange = [1 100];
XPlotToInterp = 0.5;
XDataToInterp = XDataRange(1) + (XPlotToInterp - XPlotRange(1))*diff(XDataRange)/diff(XDataRange);
XData1 = floor(XDataToInterp);
XData2 = ceil(XDataToInterp);
YInterp = interp1([XData1 XData2], [YData(XData1) YData(XData2)], XDataToInterp);

Here YInterp is the interpolated y-value for the corresponding x-value. 这里YInterp是对应x值的内插y值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM