trouble with saveTableCopy

Dear Igor guru,

I am having trouble outputting the table content. The macro "AUC curve fitting FFTs-individual" appears to create the correct waves to calculate the correct AUC by  FaverageXY (checked manually). However, in the output .cvs table, all the outputs are "0". It feels like the SaveTableCopy command won't run until the "for" loop completes when columns in the output table are deleted (therefore, the numbers turn "0"). Is this the case?

Thanks,

Judy

//===============================================================================================
function DeleteWaves(strToDelete)		//delete logFvector and noNegativeSigFit waves 

	string strToDelete
	string wList = Wavelist(strToDelete, ";", "")
	variable nWaves = itemsinList(wList)
	string wName
	variable i
	
	for (i=0; i<nWaves; i+=1)
		wName = stringfromList(i, wList)
		killWaves/Z $wName
	endfor

end
//===============================================================================================
//===============================================================================================
menu "Macros"
	"AUC curve fitting FFTs_individual", createAUCCurveFittingIndividualFFTsDialog()
End

Function createAUCCurveFittingIndividualFFTsDialog()

	setDataFolder root:BOSS3_450sub:
	DFREF dfr = GetDataFolderDFR()
	string folderName, trialName, path
	variable numDataFolders = CountObjectsDFR(dfr, 4)	
	variable i, c, trialNumber
			
	for(i=0; i < numDataFolders; i += 1)
	
		folderName = getIndexedObjNameDFR(dfr, 4, i)
		SetDataFolder ":'" + folderName + "':"
		//DFREF dfr = GetDataFolderDFR()
		
		edit/N=outputTable_AUCfittedFFT
		appendtoTable/W=outputTable_AUCfittedFFT root:AUCsegmentation
	
		make/O/T/FREE stimList = {"PDmm", "BPD", "R1", "R2", "postR", "B1", "B2", "postB"}

		make/O/N=16 PDmm
		make/O/N=16 BPD
		make/O/N=16 R1
		make/O/N=16 R2
		make/O/N=16 postR
		make/O/N=16 B1
		make/O/N=16 B2
		make/O/N=16 postB
	
		appendtotable/W=outputTable_AUCfittedFFT PDmm, BPD, R1, R2, postR, B1, B2, postB

		for (trialNumber=1; trialNumber<=2; trialNumber +=1)

			trialName="trial"+num2str(trialNumber)	
			path= "root:BOSS3_450sub:'"+folderName+"':'"+trialName+"'"
			SetDataFolder path	
			
			duplicate $"PDmm_gap_avgEye_interpolate_avgRepeat_FFT", $"PDmm_gap_avg_PDmm_FFT"

			for (c=0; c<8; c += 1)	//add 8 AUC_sigFit_FFTs to tables
			
				//obtain logFvector
				string FvectorName = "Fvector_"+stimList[c]
				string logFvectorName = "log"+FvectorName
				duplicate/O root:Fvector:$FvectorName, $logFvectorName 
				wave logFvector = $logFvectorName
				logFvector = log(logFvector) 		//obtain logFvector

				string FFTName = "PDmm_gap_avg_"+stimList[c]+"_FFT"
				string logFFTName = "log"+FFTName
				duplicate/O $FFTName, $logFFTName
				wave logFFT = $logFFTName
				logFFT = log(logFFT)	//obtain logFFT
			
				//fit FFT with sigmoid function
				string sigFitName = "sigFit_"+FFTName
				string noNegative_sigFitName = "noNegative_"+sigFitName
				wavestats/Q logFvector
				make/O/N=(V_npnts) $sigFitName
				wave sigFit = $sigFitName
				curveFit Sigmoid logFFT/X=logFvector /D=sigFit
				duplicate/O sigFit, $noNegative_sigFitName
				wave sigFitnoNegative = $noNegative_sigFitName
				sigFitnoNegative = sigFit[p] < 0 ? 0 : sigFit[p]		//set the negative portion of sigFit to 0 for AUC calculation
				//obtain AUC and post to outputTable
				wave pupCategory = $stimList[c]
				pupCategory[(trialNumber-1)*8] = FaverageXY(logFvector, sigFitnoNegative, -4, -2)
				pupCategory[(trialNumber-1)*8+1] = FaverageXY(logFvector, sigFitnoNegative, -2, -1.5)
				pupCategory[(trialNumber-1)*8+2] = FaverageXY(logFvector, sigFitnoNegative, -1.5, -1)
				pupCategory[(trialNumber-1)*8+3] = FaverageXY(logFvector, sigFitnoNegative, -1, -0.5)
				pupCategory[(trialNumber-1)*8+4] = FaverageXY(logFvector, sigFitnoNegative, -0.5, 0)
				pupCategory[(trialNumber-1)*8+5] = FaverageXY(logFvector, sigFitnoNegative, 0, 0.5)
				pupCategory[(trialNumber-1)*8+6] = FaverageXY(logFvector, sigFitnoNegative, 0.5, 1)
				pupCategory[(trialNumber-1)*8+7] = FaverageXY(logFvector, sigFitnoNegative, 1, 1.5)

			endfor


		endfor
					
		//export outputTable
		SaveTableCopy/P=home/T=2/W=outputTable_AUCfittedFFT as "AUCSigFit"+"_"+folderName+".csv"
	
		killwindow/Z outputTable_AUCfittedFFT

		SetDataFolder root:BOSS3_450sub:
		SetDataFolder ":'" + folderName + "':"

		DeleteWaves("PDmm*")
		DeleteWaves("BPD*")
		DeleteWaves("R1*")
		DeleteWaves("R2*")
		DeleteWaves("postR*")
		DeleteWaves("B1*")
		DeleteWaves("B2*")
		DeleteWaves("postB*")
		
		for(trialNumber=1;  trialNumber<=2; trialNumber +=1)
			trialName="trial"+num2str(trialNumber)	
			path= "root:BOSS3_450sub:'"+folderName+"':'"+trialName+"'"
			SetDataFolder path				

			DeleteWaves("logFvector*")
			DeleteWaves("noNegative*")
					
		endfor
		
		setDataFolder root:BOSS3_450sub:
		DFREF dfr = GetDataFolderDFR()
				
	endfor
	
end

//===============================================================================================//

 

As you build windows like graphs or tables, the changes don't get finalized until the window is drawn. For command-line changes, the redraw happens automatically when the command finishes executing. But updating and redrawing windows doesn't happen while a user function is executing unless you request it by calling `DoUpdate`. I think adding a call to `DoUpdate` just before you call `SaveTableCopy` will fix your problem.

I think John is right - DoUpdate will make your function work as expected.

Alternatively, you can create the .csv file without the use of a table using the Save operation as illustrated here:

Function Test()
	SetDataFolder root:

	Make/O/N=5 AUCsegmentation
	
	NewDataFolder/O/S root:TestDataFolder
	Make/O/N=5 PDmm, BPD, R1, R2, postR, B1, B2, postB
	
	String list = "root:AUCsegmentation;"
	list += "PDmm;BPD;R1;R2;postR;B1;B2;postB;"
	
	String fileName = "AUCSigFit" + "_" + "Test" + ".csv"
	Save /J /B /DLIM="," /P=home list as fileName
	
	SetDataFolder ::
End

 

I added DoUpdate before the saveTableCopy command and still have "0" in the output table. Any idea? 

		DoUpdate
		SaveTableCopy/P=home/T=2/W=outputTable_AUCfittedFFT as "AUCSigFit"+"_"+folderName+".csv"

 

Can you post an Igor experiment file with data and instructions on how to run it?

You might also try to debug the code yourself using Igor's symbolic debugger. The debugger allows you to single-step through the code watching how things change as the code runs. Read about it: DisplayHelpTopic "The Debugger"

Replace the DoUpdate with Abort and check the table which this will generate. Verify that you indeed have numbers in the table before you try to save it. Then we will know where the problem is. 

Via debugging, I found the problem to be "make/O/N=16 PDmm, BPD, R1, R2, postR, B1, B2, postB". These waves are made outside the "trialNumber" for-loop and not accessible at the last step of "pupCategory" (it gives an error message of "operating on a null wave".). I moved the "make..." code to inside the "trialNumber" loop and it worked!

Thank you,

Judy