Function with flexible number of arguments
Peeyush Khare
Hi,
I am trying to create a simple engine. The job of the engine is to delete certain rows from whatever number of waves are put in as arguments. How can I write a function that could take variable number of arguments?
For example: Function delengine(a,b,c) will take 3 waves. So it's a rigid function in that sense. But I want delengine to be flexible in that I want to be able to give it just a, just a and b, a and b and c, or any other number of arguments on which I to act.
Kindly advise whether this possible.
Sincerely,
Peeyush
You can create a function with a variable number of parameters using optional parameters. For details, execute:
DisplayHelpTopic "Optional Parameters"
However, I don't recommend using optional parameters for this purpose.
Instead use a single wave wave parameter. (A wave reference wave is a wave containing wave references.) For example:
WAVE/WAVE ww // A wave containing wave references
int startPoint // Starting point number (assumed valid)
int numPoints // Number of points to delete (assumed valid)
int numWaves = numpnts(ww)
int i
for(i=0; i<numWaves; i+=1)
WAVE w = ww[i]
DeletePoints startPoint, numPoints, w
endfor
End
You can test this function as follows:
Edit aWave,bWave,cWave
DemoWaveWave({aWave,bWave,cWave}, 8, 2)
DemoWaveWave({bWave}, 5, 3)
October 15, 2021 at 03:29 am - Permalink
Great, hrodstein! Thank you so much for the advice! I very much appreciate it. I'll try this out and be back if still troubles.
October 16, 2021 at 10:38 am - Permalink