How do I calibrate array in MATLAB using 3 variables??

27 views (last 30 days)
Michael on 14 Aug 2015
Commented: Brian Neiswander on 18 Aug 2015
I have:
a = (1000,1)
b = (1000,1)
c = (1000,1)
diff = (1000,1)
a and b should have similar values (i.e. profiles) to each other but there is a difference (diff). Variable a needs to be corrected ( calibrated) so that the profile looks more similar to b (as b = true values). It seems the difference in the top 100 rows are related to variable c.
I have the equation of a straight line by using polyfit and polyval, but I'm not sure now how best to proceed. I wondered if anyone knows a great function / set of functions to use to calibrate variable a using var b, c, and diff?
As well as this, It would be nice to obtain the 95% and 99% confidence levels, residuals, errors (e.g. residual standard error), and standard deviations, of both the prediction and regression lines.
Currently using MATLAB R2014b
Thanks,
Michael

Brian Neiswander on 17 Aug 2015
I understand that you have three distinct vectors "a", "b", and "c". From your descriptions:
• "a" contains un-calibrated measurements,
• "b" contains the true values,
• "c" contains values related to the difference between "a" and "b"?
• "diff" equal to the difference between "a" and "b"?
I am not clear of the role of the vectors "c" and "diff" in your analysis. I am going to assume that you are trying to do a linear calibration of the form below:
b = K*a + Z
As you mentioned, you can use the "polyfit" and "polyval" functions to accomplish this. If you have the "Curve Fitting Toolbox", I would recommend using the "fit" function:
[myfit,gof,out] = fit(a,b,'poly1');
This produces a curve fitting object "myfit". You can find goodness-of-fit information inside the "gof" structure and residual information inside the "out" structure.
Note that you can perform more complicated fitting (multi-variate, custom equations) with "fit", as demonstrated in the "Examples" section of the documentation link below:
You can plot the fit using:
plot(myfit,a,b);
You can use the "confint" and "predint" functions to get the confidence and prediction intervals for the fit.
Brian Neiswander on 18 Aug 2015
To apply the calibration stored in "myfit" to the data in the vector "a", you can simply use:
aCorrected = myfit(a);
The variable "aCorrected" will contain the corrected values of "a" using the fit that was calculated in my post above.
It becomes a bit more complicated if you want to investigate whether the temperature in "c" influences the measurements. I would suggest opening up the "Curve Fitting Tool" by typing the following into the MATLAB command window:
cftool
Note that this tool requires that you have the "Curve Fitting Toolbox" installed. Once the tool is open, you can use the graphical interface to select your variables and quickly test out different fitting options. If you have a guess as to how temperature influences the measurements then you can form a custom equation and see how well it fits your data.

Community Treasure Hunt

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

Start Hunting!

Translated by