Do loop in Macro
duncan86
In a macro I want to create a certain number ("points") of waves. Every wave has to contain the data corresponding to a gaussian peak (see the script).
As you can see in the script, every gaussian peak (so every wave) is centered at 40, while I want the peaks to be centered at the values contained in a wave0 already present in the main folder (it is given by the instrument, I work with X-rays). The wave0 has the same number of points as the number of the gaussian waves. I am not able to implement it with the do cycle, somebody can help me?
Many thanks in advance for your suggestions.
macro Simulation(points,FWHM,theta)
variable points
prompt points "POINT number"
variable FWHM
prompt FWHM "peak FWHM"
variable theta
prompt theta "Degree of BG"
variable i
string peak
do
peak = "peak" + num2str(i)
Make/O/N=161 $peak
$peak = 0.049 + 0.95*exp(-((BE_scale - 40)/(0.6024*(FWHM)))^2) + ((theta)*((BE_scale - 40)/(1+abs(BE_scale - 40))))
i+=1
while(i<points)
end macro
variable points
prompt points "POINT number"
variable FWHM
prompt FWHM "peak FWHM"
variable theta
prompt theta "Degree of BG"
variable i
string peak
do
peak = "peak" + num2str(i)
Make/O/N=161 $peak
$peak = 0.049 + 0.95*exp(-((BE_scale - 40)/(0.6024*(FWHM)))^2) + ((theta)*((BE_scale - 40)/(1+abs(BE_scale - 40))))
i+=1
while(i<points)
end macro
John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
April 10, 2015 at 12:04 pm - Permalink
Many thanks John! I am new in this forum....
April 10, 2015 at 12:05 pm - Permalink
Variable points
Variable FWHM
Variable theta
prompt points "POINT number"
prompt FWHM "peak FWHM"
prompt theta "Degree of BG"
DoPrompt "Make Gaussians", points, FWHM, theta
if (V_flag == 0)
Simulation(points,FWHM,theta)
endif
end
Function Simulation(points,FWHM,theta)
variable points
variable FWHM
variable theta
variable i
string peak
WAVE wave0
WAVE BE_scale // I'm guessing that this is a wave because of the way it's used below
for (i = 0; i<points; i+=1)
peak = "peak" + num2str(i)
Make/O/N=161 $peak/WAVE=wout
Variable x0 = wave0[i]
wout = 0.049 + 0.95*exp(-((BE_scale - x0)/(0.6024*(FWHM)))^2) + ((theta)*((BE_scale - x0)/(1+abs(BE_scale - x0))))
endfor
end
John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
April 10, 2015 at 12:11 pm - Permalink
Only another question: I am going through the other items in the forum and I see that, like you, many experts suggest the use of user defined functions instead of macros. Is it because functions can work faster and more efficient than macros?
Again thanks for your help.
April 10, 2015 at 12:36 pm - Permalink
John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
April 10, 2015 at 02:37 pm - Permalink
Thanks again for the great help,
Have a nice WE.
April 10, 2015 at 04:28 pm - Permalink
I would love to do that, but for creating complex GUIs, the window recreation macros are so much more practical than hand editing code in functions.
April 14, 2015 at 01:27 am - Permalink
Larry Hutchinson
WaveMetrics
support@WaveMetrics.com
April 14, 2015 at 09:36 am - Permalink
And, in fact, Igor generates macros for that purpose.
But I find that when putting together a complex UI using a control panel, a recreation macro rarely captures the complexity I need. I usually mock up the panel in draw mode, generate a recreation macro, and when I'm satisfied, I convert the macro to a function and add the complexity I need. But I agree that it can be excruciating when you figure out later that you want the controls to be in different places!
However, check out Jim's procedure to help with problems like that:
#include <Rewrite Controls Position>
John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
April 14, 2015 at 09:39 am - Permalink