Creating a wave from the history created by a curvefitting operation

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 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 SplitString instead of sscanf. It requires Igor Pro 6.0 or greater.

Function getwave_fromhistory()
       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.

Forum

Support

Gallery

Igor Pro 8

Learn More

Igor XOP Toolkit

Learn More

Igor NIDAQ Tools MX

Learn More