How do I plot data generated from my function? Sorry I am new to the programming. We have made variables and did a do loop to generate repeated variables at different times. We can't even plot this without transferring it to excel. I know there are functions to do this in Igor. Can anyone point me to the right spot in the manual or know how to make a simple code to graph data? Or even how to make a data folder where we can graph it then?
Here is a simplified example that might give you the idea:
Function DoSimulationForOnePoint(pointNum, a, b) Variable pointNum Variable a, b
Variable val
val = a * pointNum + b return val End
// RunSimulation(a, b, n, out) // Example: RunSimulation(1, 0, 10, "run1") // Example: RunSimulation(.1, 0, 10, "run2") Function RunSimulation(a, b, n, out) Variable a // y = ax + b Variable b // y = ax + b Variable n // Number of points String out // Name of output wave
* change your do/while loop to a for/endfor loop
* create waves to store your values
* store each iteration
nt = Ttot/dT
make/O/N=(nt) VmmV, tms, nm, hw
for (ic=0;ic<nt;ic+=1)
// your loop code here
VmmV[ic] = Vm; tms[ic] = t*1000; nm[ic] = n; hw[ic] = h
endfor
After you run the procedure, you can use display to show any one or multiple sets of the the waves.
HTH
--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAHuntsville
December 6, 2010 at 11:13 am - Permalink
Variable pointNum
Variable a, b
Variable val
val = a * pointNum + b
return val
End
// RunSimulation(a, b, n, out)
// Example: RunSimulation(1, 0, 10, "run1")
// Example: RunSimulation(.1, 0, 10, "run2")
Function RunSimulation(a, b, n, out)
Variable a // y = ax + b
Variable b // y = ax + b
Variable n // Number of points
String out // Name of output wave
Make/O/N=(n) $out
Wave wOut = $out // Create wave reference
Variable i
for(i=0; i<n; i+=1)
Variable val
val = DoSimulationForOnePoint(i, a, b)
wOut[i] = val
endfor
Display wOut
End
I split the number crunching into a subroutine (DoSimulationForOnePoint) so that the structure of the main routine (RunSimulation) remains clear.
In this case, it could be simplified to this:
and simplified further to:
December 6, 2010 at 03:01 pm - Permalink