how to access (or copy) the W_coef and W_sigma from CurveFit in a user defined procedure

Hi all, I am still new with Igor. Currently, I am trying to fit a series of histogram with Gaussian equation. The code seems to work. However the problem is how to retain/copy the fitting coefficient and other fitting information. The waves containing this information is updated in each iteration. I also didn't manage to copy them in my function. For some reasons, W_coef and  W_sigma waves are unknown. My code is as the following:
#pragma TextEncoding = "UTF-8"
#pragma rtGlobals=3     // Use modern global access method and strict wave access.

Function medianGaussian(JVmatrice)

    wave JVmatrice // 2D wave
    Variable sum=0
    Variable i=0 // We use i as the loop variable.
    Make/O/N=(dimSize(JVmatrice,1)), JV
    Make/O/N = (dimSize(JVmatrice,0)), tempwave
    Make/N=800/O tempHist;DelayUpdate

    do
        tempwave = JVmatrice[p][i]
        JV[i]=median(tempwave)
        Histogram/C/B={-7,0.1,800} tempwave,tempHist;DelayUpdate
        CurveFit gauss tempHist /D
        print(JV[i])

        //calculate inter quartile range
        //print(W_coef[1])
        //print(W_coef[2])
        //print(W_coef[3])
        //print(W_coef[4])

        i += 1
    while(i < dimSize(JVmatrice,1))
    return JV[i-1] 
End

 

You just need to declare the waves and then you can use them.

WAVE/Z W_coef,W_sigma

 

Thanks for the suggestion sjr51. It totally works.

Thank you also for the suggestion about posting the code chozo and JimProuty.

The latest version of the code is the following:

#pragma TextEncoding = "UTF-8"
#pragma rtGlobals=3     // Use modern global access method and strict wave access.
//in progress by Andika Asyuda
Function medianGaussian(JVmatrice)
    wave JVmatrice // 2D wave
    WAVE/Z W_coef,W_sigma, W_StatsQuantiles
    Variable sum=0
    Variable i=0 // We use i as the loop variable.
    Make/O/N=(dimSize(JVmatrice,1)), JVmedian //define 4 empty waves to save median, interquartile range,
    Make/O/N=(dimSize(JVmatrice,1)), JVIQR   //Gaussian mean, and standard deviation
    Make/O/N=(dimSize(JVmatrice,1)), JVGmean
    Make/O/N=(dimSize(JVmatrice,1)), JVGsigma
    Make/O/N = (dimSize(JVmatrice,0)), tempwave
    Make/N=800/O tempHist;DelayUpdate
    do
        tempwave = JVmatrice[p][i]
        statsQuantiles tempwave
        JVmedian[i]=W_StatsQuantiles[2] //take median value from W_StatsQuantiles wave
        JVIQR[i]=W_StatsQuantiles[5] //take interquartile range value from W_StatsQuantiles wave
        Histogram/C/B={-7,0.1,800} tempwave,tempHist;DelayUpdate
        CurveFit gauss tempHist /D
        JVGmean[i]=W_coef[2] //take median value from W_StatsQuantiles wave
        JVGsigma[i]=W_coef[3] //take interquartile range value from W_StatsQuantiles wave
        i += 1
    while(i < dimSize(JVmatrice,1))
    return JVmedian[i-1]   
End