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 + bVariable b // y = ax + bVariable n // Number of pointsString out // Name of output waveMake/O/N=(n)$outWave wOut = $out// Create wave referenceVariableifor(i=0; i<n; i+=1)Variable val
val = DoSimulationForOnePoint(i, a, b)
wOut[i] = val
endforDisplay wOut
End
I split the number crunching into a subroutine (DoSimulationForOnePoint) so that the structure of the main routine (RunSimulation) remains clear.
* change your do/while loop to a for/endfor loop
* create waves to store your values
* store each iteration
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
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