Using CurveFit parameters in procedures
ali8
I am trying to implement this procedure:
#pragma rtGlobals=3 // Use modern global access method and strict wave access.
Function myAuto()
Wave Vx,i_t
Display Vx vs i_t
CurveFit/M=2/W=0 line, Vx/X=t/D
Make/N=50000/D fit
fit= W_coef[0]+W_coef[1]* i_t
Vx = Vx - fit
Save/T i_t,Vx,Vy as "aaa.itx"
End
Function myAuto()
Wave Vx,i_t
Display Vx vs i_t
CurveFit/M=2/W=0 line, Vx/X=t/D
Make/N=50000/D fit
fit= W_coef[0]+W_coef[1]* i_t
Vx = Vx - fit
Save/T i_t,Vx,Vy as "aaa.itx"
End
The problem is in W_coeff, as Igor think they are "unkown/inappropriate". How can I modify it?
For details execute:
June 9, 2013 at 02:54 pm - Permalink
Another question if possible. How to add a variable inside the wave name?
I want something like this:
for i = 001 to 100
... Vx_i ....
end for
i.e. I have lots of files that differs in name, Vx_001, Vx_002, ..., Vx_999 etc.
I know this should be easy in VB or C++ but not sure how it works in Igor.
June 10, 2013 at 07:08 am - Permalink
wave i_t
variable i
for (i=0; i<itemsinlist; i+=1)
wave w = $(stringfromlist(i, list, ";")) //wave reference to i-th wave in list
CurveFit/M=2/W=0 line, w/X=t/D
//rest of code dealing with results
endfor
Since you will be dealing with a large number of waves, you will want to re-think how you store/save the results. You may not want to create a *.itx file for every single wave (or maybe you do).
June 10, 2013 at 07:32 am - Permalink
Variable i
for(i=0; i<100; i+=1)
String name
sprintf name, "Vx_%d", i
Make /O /N=(50) /D $name
Wave w = $name
w = i
endfor
End
For details:
DisplayHelpTopic "Converting a String into a Reference Using $"
June 10, 2013 at 07:35 am - Permalink
Thanks for the responses.
@Proland, I got an error in the 2nd semicolon in the for loop statement, "expected left parenthesis".
Also, I must clarify that there exist no waves such as Vx_25, for example. What exist is Vx_025. This means that all the numbers should be formatted accordingly. In VB, this is done using
i = Format(i, String(3, "0"))
EDIT: of course I can use three loops plus some if statements, but if there's a ready formatting option it would be nice.
EDIT: I figured it out. I used
sprintf name1, "VT%03d_S1Vx_V", i
June 10, 2013 at 08:31 am - Permalink
My bad, I was in a rush,
Also, the formatting of the numbers doesn't matter in my case since it looks up the actual names of waves that exist.
June 10, 2013 at 09:50 am - Permalink
June 10, 2013 at 10:04 am - Permalink
I was trying to save the waves automatically. I used:
Wave W_coef
Variable i
for(i=7; i<168; i+=1)
String name5
sprintf name5, "C:\Users\[username]\Desktop\VT%03d.itx",i
(some code here)
Save /T/M="\r\n" w2,w1,w4,w6,w7,w8 as name5
endfor
End
but that did not work. The manual says there's a flag /P to be used as Path but did not work also.
June 10, 2013 at 11:56 am - Permalink
June 10, 2013 at 12:22 pm - Permalink
I am sorry for all of these questions. At least I am trying and I solved some of them myself.
But there's a serious problem.
The data being saved is not correct, or more precisely it shows (in notepad) as NaN.
Here's the code:
Function BatchFit()
Wave W_coef
Variable i
for(i=7; i<11; i+=1)
String name1,name2,name3,myFileName
sprintf name1, "VT%03d_S1Vx_V", i
sprintf name2, "VT%03d_S1t_ms", i
sprintf name3, "fit%d", i
sprintf myFileName, "VT%03d.itx", i
Wave w1=$name1
Wave w2=$name2
Wave w3=$name3
Display w1 vs w2
Make/N=50000/D $name3
CurveFit/NTHR=0 poly 5, w1 /X=w2 /D
w3 = w_coef[0] + w_coef[1] *w2 + w_coef[2] *w2*w2 + w_coef[3] *w2*w2*w2 + w_coef[4] *w2*w2*w2*w2
w1 = w1 - w3
Save /P=mypath_fit /T/M="\r\n" w2,w1 as myFileName
endfor
End
Here w1 is shown (in notepad) as NaN, while w2 is intact. What is the problem? When I redo exactly the same steps without the procedure (i.e. manually) it works well.
June 10, 2013 at 01:51 pm - Permalink
should be after
Also make sure that the debugger is turned on:
and that "Debugging on Error" and "NVAR SVAR WAVE Checking" are turned on.
Set a breakpoint in the function and use the debugger to examine the various wave references and the waves to which they point.
June 10, 2013 at 11:36 pm - Permalink
I don't know why, although the W_coef wave generated by Igor is OK. All I have done is to take its elements and use them in my code, not sure why it does not work.
Specifically, the debugger shows (on top) the following: a wave read error: "Attempt to operate on a null (missing) wave"
June 11, 2013 at 07:43 am - Permalink
June 11, 2013 at 07:56 am - Permalink
Thanks a lot. I am grateful for you and hrodstein.
June 11, 2013 at 08:17 am - Permalink
Thanks.
August 12, 2013 at 01:07 pm - Permalink