Using cellfun to automate data calibration - issue defining function
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I am in the process of writing a code to calibrate geochemical data. One step of the code involes a linear calibration of measured & known standard values:
calibration_d18O = fitlm(std_d18O_meas, std_d18O_known);
I then extract the coefficents (slope & intercept) of the linear model fit:
coeff1 = calibration_d18O.Coefficients{2,1};
coeff2 = calibration_d18O.Coefficients{1,1};
Then I use cellfun to apply the calibration function to a cell array containing the data for different samples, using a function that I'm trying to define from the linear model fit above.
calibrated_d18O = cellfun(@(x)cal_d18O(x(4:end,4)), A, 'Unif', 0);
function f = cal_d18O(x, coeff1, coeff2)
f = x.*coeff1+coeff2;
end
I'm getting an error:
Not enough input arguments.
Error in picarro_processing_code_v2>cal_d18O (line 90)
f = x.*coeff1+coeff2;
Error in picarro_processing_code_v2>@(x)cal_d18O(x(4:end,4)) (line 70)
calibrated_d18O = cellfun(@(x)cal_d18O(x(4:end,4)), A, 'Unif', 0);
Error in picarro_processing_code_v2 (line 70)
calibrated_d18O = cellfun(@(x)cal_d18O(x(4:end,4)), A, 'Unif', 0);
I have found that when I replace coeff1 and coeff2 in the function with numerical values (i.e., for this run they are 1 and -1, but they'll be different for every single run so it needs to pull them automatically from the linear model fit). I think I am doing something wrong with the way I've written my function. Any advice greatly appreciated. Thank you :)
0 commentaires
Réponse acceptée
Walter Roberson
le 28 Avr 2023
calibrated_d18O = cellfun(@(x)cal_d18O(x(4:end,4), coeff1, coeff2), A, 'Unif', 0);
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Cell Arrays dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!