Dependecy and data folders
I've written a procedure to calculate a center of mass and wanted to implement a variable dependency and a folder creation in the procedure.
I would like to be able to change the variable offset (without having to alter the procedure itself), in the command window or in the button in the graph, and for each time I do it a new folder would be created.
I would apreciate very much if my mistakes could be pointed out in my code below
Thanks in advance,
Gabriel
#pragma rtGlobals=1 // Use modern global access method.
Function COM(w)
Wave w
Variable pw = 1
Variable/G offset = 100
Variable i, j, k
String dfName
sprintf dfName, "offset%d", offset
NewDataFolder/O/S $dfName
MAKE /N=(512,41,61) vc
Wave vc
MAKE /N=(41,61) Tintensity
Wave Tintensity
MAKE /N=(41,61) rowXintensityXpw
Wave rowXintensityXpw
MAKE /N=(41,61) CM
Wave CM
vc = w - offset //SetFormula vc, "w - offset" => Can't get this dependency to work
for (k=0; k < 61; k += 1)
for (j=0; j < 41; j += 1)
for (i=0; i < 512; i += 1)
Tintensity[j][k] += vc[i][j][k]
rowXintensityXpw[j][k] += (i+1)*vc[i][j][k]*pw
endfor
endfor
endfor
CM = (rowXintensityXpw)/(Tintensity)
Duplicate CM, CM2
Duplicate Tintensity, TI
Redimension/N=2501 CM2
Redimension/N=2501 TI
Display CM2 vs TI
ControlBar 23
SetVariable offset,size={120, 20}, value=offset
SetVariable offset, proc=COM // Set procedure to run when value is changed
SetDataFolder ::
end
January 22, 2012 at 08:37 pm - Permalink
January 22, 2012 at 11:00 pm - Permalink
Thank you for pointing that out, I'd apreciate if you told me how can I do it better.
January 23, 2012 at 06:26 am - Permalink
Which Howard did in his direct response from WM support.
John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
January 23, 2012 at 10:50 am - Permalink
Not really. I pointed out that this:
can be written as this:
That still leaves a triple-nested loop. I don't know how to simplify that. Perhaps someone else does.
My advice on the structure of the function, which I will send directly, is to avoid the use of dependencies, and to separate calculation from graphics and user-interface.
January 23, 2012 at 12:48 pm - Permalink
So how about adding the solutions here for the benefit of everyone else? Others could be interested as well.
January 23, 2012 at 12:49 pm - Permalink
They're in my post above. I beat your post by 1 minute :)
January 23, 2012 at 05:56 pm - Permalink
January 23, 2012 at 08:07 pm - Permalink
January 24, 2012 at 03:13 pm - Permalink