How to make do-while function work? Thanks
llzy36
I'm a newer to learn the igor procedure. I made a procedure about how the celsius degree change to Fahrenheit degree. The result sholud be two column showing these two temperature. Can somebody help me to check my procedure where was wrong.
Thank you very much.
Best wishes
Function Change()
variable fahr, celsius
variable lower, upper, step
lower=0
upper=301
step=20
fahr=lower
do
fahr+=20
celsius=5*(fahr-32)/9
while(fahr print fahr, celsius
end
January 12, 2016 at 03:09 am - Permalink
This function will create two waves (arrays) and display them in a table.
variable fahr, celsius
variable lower, upper, step
Variable Numpts, Index
lower=0
upper=301
step=20
Index = 0
Numpts = Round((upper - lower)/step) + 1
//create waves (arrays) to hold temperature data
// "/O" overwrites a wave if it already exists
make /O/N=(Numpts) wFahrenheit, wCelsius
fahr=lower
do
celsius=5*(fahr-32)/9
WFahrenheit[Index] = fahr
wCelsius[Index] = celsius
fahr+=step
Index += 1
while(Index < Numpts )
Edit wFahrenheit, wCelsius
End
The following function will print results directly to the history window, without the need for creating waves. Maybe this is what you had in mind.
variable fahr, celsius
variable lower, upper, step
Variable Numpts
lower=0
upper=301
step=20
Numpts = Round((upper - lower)/step) + 1
fahr=lower
printf "%10s %10s\r", "Fahrenheit", "Celsius"
do
celsius=5*(fahr-32)/9
//print fahr, celsius
printf "%10.2f %10.2f\r", fahr, celsius
fahr+=step
while(fahr < upper )
End
History window display:
Fahrenheit Celsius
0.00 -17.78
20.00 -6.67
40.00 4.44
60.00 15.56
80.00 26.67
100.00 37.78
120.00 48.89
140.00 60.00
160.00 71.11
180.00 82.22
200.00 93.33
220.00 104.44
240.00 115.56
260.00 126.67
280.00 137.78
300.00 148.89
January 12, 2016 at 06:09 am - Permalink
DisplayHelpTopic "Waveform Arithmetic and Assignment"
variable lower, upper, step
variable nPoints = floor((upper-lower)/step) + 1
Make/O/D/N=(nPoints) Fahrenheit, Celsius
SetScale/P x, lower, step, "°F", Fahrenheit
Fahrenheit = x
Celsius = 5 * (Fahrenheit-32) / 9
end
Then execute:
change3(0, 300, 20)
January 13, 2016 at 02:15 am - Permalink