![](/profiles/wavemetrics/themes/wavemetrics/logo.png)
Dependecy and data folders
![](/sites/default/files/styles/thumbnail/public/default_images/Artboard%201_1.png?itok=jeHOCIXy)
gzvitiello
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
<br /> #pragma rtGlobals=1 // Use modern global access method.<br /> <br /> Function COM(w)<br /> <br /> Wave w<br /> <br /> Variable pw = 1 <br /> Variable/G offset = 100<br /> Variable i, j, k<br /> String dfName<br /> sprintf dfName, "offset%d", offset<br /> <br /> NewDataFolder/O/S $dfName<br /> <br /> MAKE /N=(512,41,61) vc<br /> Wave vc<br /> <br /> MAKE /N=(41,61) Tintensity<br /> Wave Tintensity<br /> <br /> <br /> MAKE /N=(41,61) rowXintensityXpw<br /> Wave rowXintensityXpw<br /> <br /> <br /> MAKE /N=(41,61) CM<br /> Wave CM<br /> <br /> <br /> vc = w - offset //SetFormula vc, "w - offset" => Can't get this dependency to work<br /> <br /> for (k=0; k < 61; k += 1)<br /> for (j=0; j < 41; j += 1)<br /> for (i=0; i < 512; i += 1)<br /> Tintensity[j][k] += vc[i][j][k]<br /> rowXintensityXpw[j][k] += (i+1)*vc[i][j][k]*pw<br /> endfor<br /> endfor<br /> endfor<br /> <br /> CM = (rowXintensityXpw)/(Tintensity)<br /> <br /> Duplicate CM, CM2<br /> Duplicate Tintensity, TI<br /> <br /> Redimension/N=2501 CM2<br /> Redimension/N=2501 TI<br /> <br /> Display CM2 vs TI<br /> ControlBar 23<br /> SetVariable offset,size={120, 20}, value=offset<br /> SetVariable offset, proc=COM // Set procedure to run when value is changed<br /> SetDataFolder ::<br /> <br /> end<br /> <br /> </span>
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