Use $integral $ and $fzero$ with ksdensity

1 view (last 30 days)
Hello, I have been looking for finding the intersection of two outputs of ksdensity, as well as integrating the difference of the two questions. Can you please see the code, you might understand what I am trying to say:
xlsread('Sheet1.xlsx','Hourly Data','B:B'); % load Data
Load = xlsread('Sheet1.xlsx','Hourly Data','D:D'); %load Data
[f_re,xr] = ksdensity(RE); % to return the 1st pdf
[f_lo,xl] = ksdensity(Load); %returns the 2nd pdf
figure
plot(xl,f_lo,xr,f_re); % plot
f1=@(x) f_re(x); % and starting from this line , things are getting complicated
f2=@(x) f_lo(x);
Pl=fzero(f1-f2,0); % trying to find the intersections of the two functions may be
q = integral(f1-f2,0,inf); % integrating the difference ?
And obviously, Matlab does return errors. I do not know how to do all of this, Could you please give me some hints! Thank you so much.

Accepted Answer

Walter Roberson
Walter Roberson on 29 Sep 2016
Pl=fzero(@(x) f1(x)-f2(x),0); % trying to find the intersections of the two functions may be
q = integral(@(x) f1(x)-f2(x),0,inf); % integrating the difference ?
You cannot add or subtract function handles: you have to call the function handles with arguments and add or subtract the results.
  2 Comments
Imane Imane
Imane Imane on 29 Sep 2016
Thank you for your answer. Can you please tell me how to do it, or give me a link explaining the procedure.
Walter Roberson
Walter Roberson on 29 Sep 2016
... I just did? The code I posted is the corrected code.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!