Using cellfun to automate data calibration - issue defining function

조회 수: 3 (최근 30일)
Emily
Emily 2023년 4월 28일
댓글: Emily 2023년 4월 28일
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에서 Cell Arrays에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by