Question

How can I find the exact y-coordinate of the red gaussian at x = 0.5 without using Data Cursor?

histfit plot">

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. I can access the data points of the histfit plot as follows:

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.

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?

Was it helpful?

Solution

Getting XData as well should give you the right x-values:

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.

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.

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top