Creating a wave from the history created by a curvefitting operation
Posted September 18th, 2007 by andyfaff
When you perform a fit the output often goes into the history line in the form:
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

This is a good example of
This is a good example of where using the new regular expressions operations in Igor Pro 6.0 can come in handy (though in this case using regular expressions is probably MORE difficult, unless you're already pretty familiar with regular expressions).
Here's a function that does the same thing but does so using
SplitStringinstead ofsscanf. It requires Igor Pro 6.0 or greater.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.