creating wave

Hello, I am super new to Igor and am wondering how I can write a function so that a user can pick a wave out of a stored file and the function will return that wave so that it can be used in another procedure. For example, I tried writing it with a prompt so that the user could pick the wave, but that doesn't work. Any help would be appreciated! The following is an example of what I am trying to do.
Nathan

Function MatrixChoiceX()
	string chosenxmatrix
	Prompt chosenxmatrix, "Name of the X Matrix: ",popup,wavelist("*",";","DIMS:1")
	Doprompt  "Choose the wave:", chosenxmatrix
	wave resultx = $chosenxmatrix
End
Function MatrixChoiceY()
	string chosenymatrix
	Prompt chosenymatrix, "Name of the Y Matrix: ",popup,wavelist("*",";","DIMS:1")
	Doprompt "Choose the wave:", chosenymatrix
	wave resulty = $chosenymatrix
End
Function trapezoidalpeakarea(a,b) : ButtonControl
	variable a,b   //inputted bounds given by the user
	wave xdata = MatrixChoiceX()
        wave y data = MatrixChoiceY()
	Prompt a, "Lower bound of the peak:"
	Prompt b, "Upper bound of the peak:"
	DoPrompt "Select the waves and set the upper and lower bounds of peak region", a,b
	variable result = 0
	variable i
	for (i=a; i <= (b-1); i += 1)
		result = result + (xdata[i+1]-xdata[(i)])*((ydata[i]+ydata[(i+1)])/2)
	endfor
	return result
End



I haven't run it, but the following revision should work.

Function/WAVE MatrixChoiceX()
	string chosenxmatrix
	Prompt chosenxmatrix, "Name of the X Matrix: ",popup,wavelist("*",";","DIMS:1")
	Doprompt  "Choose the wave:", chosenxmatrix
	wave resultx = $chosenxmatrix
	return resultx
End
Function/WAVE MatrixChoiceY()
	string chosenymatrix
	Prompt chosenymatrix, "Name of the Y Matrix: ",popup,wavelist("*",";","DIMS:1")
	Doprompt "Choose the wave:", chosenymatrix
	wave resulty = $chosenymatrix
	return resulty
End
Function trapezoidalpeakarea(a,b)
	variable a,b   //inputted bounds given by the user
	wave xdata = MatrixChoiceX()
        wave ydata = MatrixChoiceY()
	Prompt a, "Lower bound of the peak:"
	Prompt b, "Upper bound of the peak:"
	DoPrompt "Select the waves and set the upper and lower bounds of peak region", a,b
	variable result = 0
	variable i
	for (i=a; i <= (b-1); i += 1)
		result = result + (xdata[i+1]-xdata[(i)])*((ydata[i]+ydata[(i+1)])/2)
	endfor
	return result
End


--Jim Prouty
Software Engineer, WaveMetrics, Inc.
Instead of computing the area yourself, perhaps use the areaXY function:


Function trapezoidalpeakarea(a,b)
	variable a,b   //inputted bounds given by the user
	wave xdata = MatrixChoiceX()
        wave ydata = MatrixChoiceY()
	Prompt a, "Lower bound of the peak:"
	Prompt b, "Upper bound of the peak:"
	DoPrompt "Set the upper and lower x bounds of peak region", a,b
	variable result = areaxy(xdata, ydata, a,b)
	return result
End


You also might want to take a look at AreaXYBetweenCursors:


#include <AreaXYBetweenCursors>



--Jim Prouty
Software Engineer, WaveMetrics, Inc.
Thank you! Another quick question, the dropbox menu seems only to bring up the current data folder I am working in, any way that I can change this so that I can browse for waves on all folders? Thanks!
nstanell wrote: Thank you! Another quick question, the dropbox menu seems only to bring up the current data folder I am working in, any way that I can change this so that I can browse for waves on all folders? Thanks!

Not really; you'd have to convert to using a panel and wave widget selector controls.

See File->Examples->Programming->WaveSelectorWidgetExample.pxp

[Edit: okay, actually you *could* write a new string function for the wave prompts that iterated all the waves in all data folders and returns a list of the full paths to those waves. The result would be somewhat unwieldy if you have a complicated datafolder hierarchy.]

--Jim Prouty
Software Engineer, WaveMetrics, Inc.
WaveSelectorWidgetExample.PNG (25.38 KB)