MultiPeak Fit results in waves?

After doing a multipeak fit, I would like to have waves containing the coefficients from the fit.  For example, if I fit to a wave that has several lorentzian peeks, I would like one wave with all the peak locations, another wave with all the peak areas, etc.   Very much like the columns in the notebook created by MPF2_TabDelimitedResultsBtnProc.  (Why does that button generate a notebook and not a table?)

We can generate that notebook and copy and paste into a way, but 1) that isn't very elegant, and 2) we lose information from the rounding that happens.  

I think the answer is that I need to write a function patterned off of MPF2_TabDelimitedResultsBtnProc, but if you have already done something like that, please let me know.

Michael

Welcome to the forum.

First, you might want to discern between coefficients (directly used as parameters in the fit) and derived values (such as FWHM or area). There about a hundred ways you can access the data and similarly many ways users might want their output formatted. Multipeak Fit offers a few of the most common ones. But there are several ways to achieve what you want very easily:

  • If you want waves with all values (both coefficients and derived), you can use the Table with Waves button, which creates a bunch of nicely formatted waves in the current data folder for you to access.
     
  • If you only want coefficients, you can also directly access the 'Peak X Coefs' (X is an integer starting from 0) waves within the current Multipeak Fit folder 'root:Packages:MultiPeakFit2:MPF_SetFolder_Y:'.
     
  • If you don't care for extreme (and unnecessary) precision and don't want to create yet more waves, you could also read the values from the MPF2_ResultsListWave text wave within the Multipeak Fit folder, which is what you see displayed in the table after pressing the Peak Results button in the first place. Since it is a text wave, you would need to convert the entries into numerical values in the process.

I usually do the last option for convenience. Here is a small script which should give you the idea:

Function GetMPFResults()
 
    int numPeaks = 3    // number of current peaks (could be set automatically)
    int numSets  = CountObjects("root:Packages:MultiPeakFit2:", 4)  // count number of sets
    
    Make/D/O/N=(numPeaks, numSets) root:all_results/WAVE=output
    int setNum, peakNum
    for(setNum = 0; setNum < numSets; setNum++)
        // set numbers start from one but wave counters start from zero!
        string folder = "MPF_SetFolder_" + num2str(setNum+1)
        Wave/T result = root:Packages:MultiPeakFit2:$(folder):MPF2_ResultsListWave
        for(peakNum = 0; peakNum < numPeaks; peakNum++)
            output[peakNum][setNum] = str2num(result[peakNum][6])   // get area of each peak
        endfor
    endfor
End

Note that, and this is important, MPF2_ResultsListWave only is updated when you press the Peak Results button and not when you do the fit. This wave is for displaying results after all and was not intended for extracting results.