Asked by Ganesh
on 1 Oct 2012

I have 2 sets of data of the same size (X1, Y1) and (X2,Y2). (X1,Y1) has a linear relationship with zero intercept (Y1=slope*X1). How can I estimate the slope, R^2 value and plot it along with 95% confidence interval lines? Using Corrcoeff, polyfit and polyval gives me a relationship of the form Y1=slope*X1 + c, but I would like to force c=0.

(X2,Y2) has a non-linear relationship of the form Y2=A-Bexp(C*X2). Likewise, I would like to determine A,B & C along with R^2 value and plot it along with 95% confidence interval lines. I know I have to use nlinfit, nlparci but I am new in this and would need your help.

Thanks much.

*No products are associated with this question.*

Answer by Star Strider
on 1 Oct 2012

Edited by Star Strider
on 1 Oct 2012

Accepted answer

You seem to be acquainted with `nlinfit` and know how to use it, but apparently not with `Anonymous Functions`.

I suggest you use `nlinfit` for both problems. With `B = [B(1)` ... `B(n)]'` a column vector of parameters, your `Y1` function becomes:

Y1 = @(B,x) B.*x;

since with only one parameter in it, you do not need to use subscripts.

Your `Y2` function becomes:

Y2 = @(B,x) B(1)-B(2).*exp(B(3).*x);

These should work as your `modelfun` functions in `nlinfit`.

Show 12 older comments

Ganesh
on 5 Oct 2012

Thank you for providing with the code. It ran smoothly. The only change I made is in the plot command. F2_est is a row array, while FitCI95 is a column array. So, I made a minor change as: plot(X2fit, F2_est'-FitCI95+0.01, ':r', 'LineWidth', 1.5) plot(X2fit, F2_est'+FitCI95, ':r', 'LineWidth', 1.5)

Thanks a ton for your help.

Star Strider
on 5 Oct 2012

** R^2:** Yes, if you use the

It is my pleasure to help!

Related Content

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi test

Learn moreOpportunities for recent engineering grads.

Apply Today
## 0 Comments