
Accessing W_coef wave after curve fit in function

Hi All: Below is a minimum non-working example of my problem. When the print statement is executed I get the error, "attempt to operate on a null (missing) wave", which, in this case, appears to be the w_coef wave that is automatically created by the CurveFit function. If I put a breakpoint just after the CurveFit operation is executed, the debugger shows w_coef as <null>. But if I stop execution at this point and then look at the data browser, w_coef exists and contains the correct fitting parameters.
If I run test() a second time it works fine.
Thus to the program w_coef has not been defined, but to Igor as a whole it has. I expect that this is one of those wave reference issues that I never have fully understood. Maybe I need to create w_coef with a Make command first?
#pragma TextEncoding = "UTF-8" #pragma rtGlobals=3 // Use modern global access method and strict wave access. function test() Wave w_coef Make data data = x CurveFit/Q line data print w_coef[1] end
Yes, you need to move the line "Wave W_coef" to a line after the call to CurveFit. To understand why, please read the help that this command takes you to:
DisplayHelpTopic "Runtime Lookup of Globals"
It explains the compile-time and run-time actions of a WAVE statement.
March 21, 2022 at 11:45 am - Permalink