Hello,
I have a set of data representing current as a function of angles as shown in the attached figure. The data sets I have are not Gaussian and I would like to find the 95% area under the curve along with the x1 and x2 position to add to the plot, but I do not have the stat or curve fit toolbox. How can I do this in Matlab?
Thanks

 Réponse acceptée

Star Strider
Star Strider le 14 Fév 2017

0 votes

Without your data, I can only outline the approach I would use. First, use the cumtrapz function to do the integration. Normalise the area to 1 by dividing the result of your cumtrapz call by the last value of the vector. Then use the interp1 function to calculate the value of the 2.5% and 97.5% values. Those will be the limits of the central 95%.

4 commentaires

Max Bernstein
Max Bernstein le 14 Fév 2017
Thank you for your help. I'm a little confused on the interpolation step. Given the example below, are you saying that the values in "int" corresponding to the "normalized" vector at 2.5 and 97.5 are the positions?
>> x =[ 0 1 2 3 4 5 6];
>> y = [0.3816 0.7655 0.7952 0.1869 0.4898 0.4456];
>> integration = cumtrapz(x,y);
>> normalized = integration/integration(end);
>> plot(x,y)
>> int = interp1(x,y,normalized);
Star Strider
Star Strider le 14 Fév 2017
My pleasure.
I should have provided an example, so I’m correcting that earlier oversight here:
x = linspace(-5, 5, 250);
f = @(x) exp(-x.^2);
y = f(x);
integration = cumtrapz(x, y);
normalized = integration/integration(end);
x_bounds = interp1(normalized, x, [0.025; 0.975]);
figure(1)
plot(x,y)
hold on
area(x(x>=x_bounds(1) & x<=x_bounds(2)), y(x>=x_bounds(1) & x<=x_bounds(2)), 'FaceColor','g')
hold off
You can probably use this code with your data without modification (unless you want a different colour for the area plot).
Max Bernstein
Max Bernstein le 15 Fév 2017
Thank you very much! I was able to get this working with my data set.
Star Strider
Star Strider le 15 Fév 2017
As always, my pleasure!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by