Code fails to run in function, works in command window, works in debug "evaluate selection"
이전 댓글 표시
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)
load lctfData
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)
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!