Creating a wave from the history created by a curvefitting operation
andyfaff
w[0] = 2
w[1] = 1.00681
w[2] = 2.07
w[3] = 6.36
...
However, many fits later, or a long time later you may have realised that the first fit was best but you overwrote it. The following snippet will use the history lines from your fit output to create a new wave containing those numbers. First of all copy the history lines to the clipboard by copying and pasting. Then call getwave_fromhistory(). It will create a wave called W_wavefromstring containing those lucky numbers
Function getwave_fromhistory()
string wavedata = getscraptext()
variable numitems = itemsinlist(wavedata,"\r")
make/o/n=(numitems) W_wavefromstring
variable ii,pos_equals,number
string parsestring
for(ii=0;ii < numitems;ii+=1)
parsestring = stringfromlist(ii,wavedata,"\r")
pos_equals = strsearch(parsestring,"=",0)
parsestring = parsestring[pos_equals+1,(strlen(parsestring))]
sscanf parsestring,"%f",number
W_wavefromstring[ii] = number
endfor
end
Forum
Support
Gallery
Igor Pro 9
Learn More
Igor XOP Toolkit
Learn More
Igor NIDAQ Tools MX
Learn More
Here's a function that does the same thing but does so using
SplitString
instead ofsscanf
. It requires Igor Pro 6.0 or greater.string wavedata = getscraptext()
variable numitems = itemsinlist(wavedata,"\r")
make/o/n=(numitems) W_wavefromstring
variable ii,pos_equals,number
string parsestring
string matchedstring
string regExp = ".+=(.+)"
for(ii=0;ii < numitems;ii+=1)
parsestring = stringfromlist(ii,wavedata,"\r")
SplitString/E=regExp parsestring, matchedstring
W_wavefromstring[ii] = str2num(matchedstring)
endfor
end
As far as I can tell this should provide the same output as Andy's function above, but just does so in a different way. There's no real advantage to using regular expressions here, but I thought I'd provide an example anyway.
September 19, 2007 at 06:08 am - Permalink