I had an extremely infuriating problem. My code evaluates differently in the command window than in a function.
It fails on peak = interp1(wvcenter, peaks, wavelength);
wvcenter is a 33x1 double, peaks is a 33x1 double, wavelength is a double
It fails to run inside the function only. I can run the same code in the command window. I can run it by debugging with a stop on line 5, highlight and evaluate selection. But it fails if I use continue or step through code. It turns out peaks is an existing function that I have been storing a value to, but why does it evaluate differently? What is wrong?
function transmission = lctfTransmission(wavelength, wavelengths)
peak = interp1(wvcenter, peaks, wavelength);
bandwidth = interp1(wvcenter, bandwidths, wavelength);
wv2 = (wv1-mean(wv1))*bandwidth/max(wv1-mean(wv1))+wavelength;
t2 = t1*peak/max(t1);
transmission = interp1(wv2, t2, wavelengths, 'linear', 0);
and the error
Error using griddedInterpolant
The grid vectors do not define a grid of points that match
the given values.
Error in interp1 (line 158)
F = griddedInterpolant(Xext,V,method);
Error in lctfTransmission (line 5)