Fit And Graph a List of XY Pairs


#pragma rtGlobals=1		// Use modern global access method.

//	Example:
//		Make/O/N=5 xWave0=p, yWave0=gnoise(1)
//		Make/O/N=5 xWave1=p, yWave1=gnoise(1)
//		String xWaveList = "xWave0;xWave1;"
//		String yWaveList = "yWave0;yWave1;"
//		FitAndGraphAllXYPairs(xWaveList, yWaveList)

Function FitAndGraphXYPair(xWave, yWave)
	Wave xWave
	Wave yWave
	
	Display yWave vs xWave
	ModifyGraph mode=3,marker=19,rgb=(0,0,65535)		// Round blue markers
	DoUpdate
	
	CurveFit /TBOX=256 line yWave /X=xWave /D
	
	String textboxName = "CF_" + NameOfWave(yWave)
	String text
	
	// Append Rab - the correlation between the intercept (a) and the slope (b)
	sprintf text, "V_Rab = %g", V_Rab
	AppendText /N=$textboxName text

	return 0					// Signifies success.
End

Function FitAndGraphAllXYPairs(xWaveList, yWaveList)
	String xWaveList			// Semicolon-separated list
	String yWaveList			// Semicolon-separated list

	String graphName
	Variable index, numXYPairs

	numXYPairs = ItemsInList(xWaveList)
	if (numXYPairs != ItemsInList(yWaveList))
		DoAlert 0, "The number of X waves must equal the number of Y waves."
		return -1
	endif
	
	for(index=0; index<numXYPairs; index+=1)
		String xWaveName = StringFromList(index, xWaveList)
		Wave xWave = $xWaveName
		String yWaveName = StringFromList(index, yWaveList)
		Wave yWave = $yWaveName

		FitAndGraphXYPair(xWave, yWave)
	endfor
	
	return 0
End


Forum

Support

Gallery

Igor Pro 10

Learn More

Igor XOP Toolkit

Learn More

Igor NIDAQ Tools MX

Learn More