Using cellfun to automate data calibration - issue defining function

1 次查看(过去 30 天)
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 :)

采纳的回答

Walter Roberson
Walter Roberson 2023-4-28
calibrated_d18O = cellfun(@(x)cal_d18O(x(4:end,4), coeff1, coeff2), A, 'Unif', 0);

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by