Difference between revisions of "Igor Quick Reference"

From Jimenez Group Wiki
Jump to: navigation, search
(Using Cursors)
(Common Keyboard Shortcuts: Add ctrl+Y)
 
(64 intermediate revisions by 4 users not shown)
Line 1: Line 1:
This page is intended to be a resource for the beginning and intermediate Igor user to quickly find help and tips about common tasks in Igor.  Much of the information on this page is taken from the Igor "Getting Started" Introduction and Guided Tour, but is organized by topic so that the information is easy to find.  Users of this page should also search (ctrl+f) for terms in case what they're looking for isn't found in the topic they expect.
+
This page is intended to be a resource for the beginning and intermediate Igor user to quickly find help and tips about common tasks in Igor.  Much of the information on this page is taken from the Igor "Getting Started" Introduction and Guided Tour, but is organized by topic so that the information is easy to find.  Users of this page should also search (ctrl+f) for terms in case what they're looking for isn't found in the topic they expect. A shorcut to this page is [http://tinyurl.com/Igor-quick http://tinyurl.com/Igor-quick]
  
 
This page was started by Ingrid Ulbrich.
 
This page was started by Ingrid Ulbrich.
 +
 +
= Common Keyboard Shortcuts =
 +
* CTRL + J --> command window
 +
** CTRL + K --> clears command line
 +
* CTRL + M --> brings the procedure window to the front
 +
* CTRL + T --> in a graph or panel, enables or disables tools
 +
* CTRL + I --> in a graph, enables cursors ("info")  (''Graph -> Show Info'')
 +
* CTRL + Y --> in a graph or table, rename window
 +
* CTRL + A --> in a table or in the command window: select all
 +
** --> in a graph: autoscale axes ''Graph -> Autoscale Axes''
 +
* Common Windows Commands
 +
** CTRL + S --> save experiment
 +
** CTRL + C, CTRL + X, CTRL + V --> copy, cut, paste
 +
** CTRL + F, CTRL + G --> find, find again (with shift, go the opposite direction)
 +
** CTRL + R --> search and replace
 +
** CTRL + P --> print
 +
** CTRL + Z --> undo (only one action before Igor 7)
 +
** CTRL + N --> new experiment
  
 
= Waves =
 
= Waves =
Line 7: Line 25:
  
 
Waves have inherent x values that are by default equal to the point number.  If you display a wave, it is automatically plotted versus the x value (0, 1, 2, etc.).  It is possible to change the inherent wave scaling (see '''setScale'''), or you can plot a y-wave versus an x-wave.
 
Waves have inherent x values that are by default equal to the point number.  If you display a wave, it is automatically plotted versus the x value (0, 1, 2, etc.).  It is possible to change the inherent wave scaling (see '''setScale'''), or you can plot a y-wave versus an x-wave.
 +
 +
Waves are global and exist until you kill them.
  
 
== Helpful Wave Functions==
 
== Helpful Wave Functions==
* '''make''' /O /N=
+
* '''make''' /O /N=''points''
 
**''Data -> Make Waves...''
 
**''Data -> Make Waves...''
  
Line 19: Line 39:
 
** when the wave is in a table, right-click and choose Reanme
 
** when the wave is in a table, right-click and choose Reanme
  
* '''setScale'''
+
* '''setScale''' ''[/I/P] dim, num1, num2''
 +
** You can change the inherent values, but not the data values
 +
** /P: num1 is start value, num2 is delta value
 +
** /I: num1 is start value, num2 is last value 
 
**''Data -> Change Wave Scaling...''
 
**''Data -> Change Wave Scaling...''
 +
 +
* '''killwaves'''
 +
** ''Data -> Kill Waves...''
  
 
== Putting Data in Waves ==
 
== Putting Data in Waves ==
Line 38: Line 64:
  
 
=== As a list of values, in the command line ===
 
=== As a list of values, in the command line ===
 +
 +
* myWave = {12, 24, 36}
  
 
=== Waves in Equations ===
 
=== Waves in Equations ===
  
==Loading Text Data==
+
You can treat a wave as a variable name in equations and assignments are made on a point-to-point (point 0, 1, etc.) basis.
 +
 
 +
For example, if you have
 +
  make/N=10 x_wave = x 
 +
you can make a wave of a line with slope 3 and intercept 4 by
 +
  make/N=10 y_wave = 3*x_wave + 4
 +
then
 +
  y_wave[0] = 3*x_wave[0] + 4
 +
  y_wave[1] = 3*x_wave[1] + 4
 +
  etc.
 +
 
 +
== Loading Data ==
 +
=== From Igor Text Files (.itx) ===
 +
* Double-click on the file icon on your computer.  Waves will be loaded into the current DataFolder
 +
* ''Data -> Load Waves -> Load Igor Text...''' and choose the appropriate file
 +
 
 +
=== From non-Igor Text Files ===
 +
* ''Data -> Load Waves -> ''' and choose to load an appropriate file type
 +
 
 +
=== From Excel Files ===
  
 
= Graphs =
 
= Graphs =
Line 58: Line 105:
  
  
== Modifying Traces ==
+
== Modifying Trace Appearance ==
 
# Getting to the window
 
# Getting to the window
 
#* Double-click on a trace
 
#* Double-click on a trace
Line 65: Line 112:
 
# Notes and Tricks
 
# Notes and Tricks
 
#* You can change several traces at once by selecting multiple waves (ctrl+click).
 
#* You can change several traces at once by selecting multiple waves (ctrl+click).
 +
#* "Offset" lets you do additive offsets (x and or y) and multiplicative scaling (x and or y)
 +
#* "Set as f(z)..." lets you set color, marker type, and marker size by any other wave of appropriate length (e.g., color by time, make marker size proportional to value)
 +
#* "Hide Trace" makes the selected trace not visible, but does not remove the associated axis. 
 +
#** If the hidden trace had the highest or lowest value and controlled the axis range, the axis range will be reset unless "Autoscale" is checked.
 +
#** This can be useful if you want to show a graph in a presentation where you show versions with more traces in each view.  This way you can make all the versions from the same graph.
 +
 +
== Reorder Traces ==
 +
 +
# Getting to the window
 +
#* Right-click in the margin of the graph
 +
#* Choose "Reorder Traces..."
 +
# Changing the order
 +
#* Drag and drop waves to change the order.
 +
#* Waves are drawn in the plot starting with the first trace (this will be furthest back visually) and ending with the last trace (on top).
  
 
== Modifying Axes ==
 
== Modifying Axes ==
Axes
 
 
# Getting to the window
 
# Getting to the window
 
#* Double-click on an axis (look for vertical or horizontal double-arrow cursor)
 
#* Double-click on an axis (look for vertical or horizontal double-arrow cursor)
Line 73: Line 133:
 
# Notes and Tricks
 
# Notes and Tricks
 
#* You can make selections to any axis (or multiple axes at the same time) from the pulldown menu at the upper left of the window.
 
#* You can make selections to any axis (or multiple axes at the same time) from the pulldown menu at the upper left of the window.
 
  
 
== Adding Text ==
 
== Adding Text ==
Line 87: Line 146:
 
* Edit an existing text box by double-clicking on it.
 
* Edit an existing text box by double-clicking on it.
  
===Tag (Text that ===
+
===Tag (Text that is associated with a point in a wave)===
 
* ''Graph -> Add Annotation...'', change the Annotation type in the upper left corner to TextBox
 
* ''Graph -> Add Annotation...'', change the Annotation type in the upper left corner to TextBox
 
* Right-click in the graph and choose "Add Annotation...", change the Annotation type in the upper left corner to TextBox
 
* Right-click in the graph and choose "Add Annotation...", change the Annotation type in the upper left corner to TextBox
Line 93: Line 152:
  
 
==="Drawn" text (less interactive than a text box)===
 
==="Drawn" text (less interactive than a text box)===
# Get to the "Tools" by pressing ctrl+t when the top window is your graph.  A set of buttons will appear to the left of your graph.
+
# Get to the "Tools" by pressing ctrl+t (''Graph -> Show Tools'') when the top window is your graph.  A set of buttons will appear to the left of your graph.
 
# Choose the "T..." icon and click in the graph where you want the text to be.
 
# Choose the "T..." icon and click in the graph where you want the text to be.
 
# Insert your text in the dialog box.  Note that you can control the location and formatting of the text here.
 
# Insert your text in the dialog box.  Note that you can control the location and formatting of the text here.
Line 100: Line 159:
 
#* After closing the dialog, you must click the arrow icon to move your text.
 
#* After closing the dialog, you must click the arrow icon to move your text.
 
#* This text can only be moved or changed when "Tools" are available.
 
#* This text can only be moved or changed when "Tools" are available.
 +
#* When "Tools" are enabled (the long list of buttons is showing) you cannot copy a graph (for pasting into a Notebook or other programs).  Close the tools (ctrl+t) or click the top button of the toolbar to allow copying.
 +
 +
 +
== Adding Straight Lines ==
 +
=== With Traces ===
 +
* Create a 2-point wave with points = 0, 1
 +
* Append this trace to the graph and scale it using multiplicative offset (same x-,y-scaling --> 1:1 line; different x-, y-scaling for different slopes)
 +
 +
=== Drawing Fixed Lines ===
 +
* Enable drawing tools by pressing ctrl+t (''Graph -> Show Tools'').
 +
* Select the line tool and draw a line.
 +
* Select the arrow tool and double-click on the line.
 +
* To make a fixed-value line, set the Coordinate System (upper left pull-down menus) to axes (e.g., "Axis Bottom", "Axis Left")
 +
* Set the coordinates in the bottom of the dialog box to the axis values for the line.  Note that (X0, Y0) is the point where you started the line.
  
== Adding Lines ==
 
 
== Using Cursors ==
 
== Using Cursors ==
 +
# Press ctrl+i or ''Graph -> Show info''
 +
# Drag the cursor icons onto points on the graph
 +
#* Note that the cursors attach only to points in a wave, not line segments
 +
#* You can change the wave that a cursor is on by right-clicking on the wave name and choosing a different name
 +
# Wave information is displayed in the bar. 
 +
# Move the cursors by pressing right and left arrow keys or by moving the vertical bar between the wave names and the point information.
 +
#* "Highlighted" (dark) markers next to the wave name indicate that the cursor will move; open markers indicate that the cursor will not move.
 +
# Tips and Tricks
 +
#* Note that point may not equal x value, depending on how your wave is plotted.
 +
#* You can get up to 10 cursors, but you can only see the info from two cursors at a time.  Right-click over the names of the waves for the cursors and select "Show Cursor Pair" for a new pair of cursors.
  
 
== Saving Graphs ==
 
== Saving Graphs ==
 
=== Graph Macro ===
 
=== Graph Macro ===
* ctrl+y
+
* ctrl+y.  To save the macro choose a name for the macro and check the box to save or update the graph macro.  You can give the graph a window title (optional).
 +
** close the graph and choose "Save"
 +
* A macro with the name you selected is created in the local procedure window (ctrl+m)
 +
* This is a handy way to get the code to produce a graph when you want to create a function that makes this graph
  
 
=== Graph Style Macro ===
 
=== Graph Style Macro ===
Line 116: Line 201:
 
= Strings =
 
= Strings =
 
== Helpful String Functions ==
 
== Helpful String Functions ==
 
+
*'''string'''/G (creates a global string)
 +
*'''num2str''' and '''str2num'''
 +
*'''stringmatch'''
 +
*'''strlen'''
 +
*'''strsearch'''
 +
*'''SVAR''' and '''SVAR_exists'''
  
 
= Variables =
 
= Variables =
 
== Helpful Variable Functions ==
 
== Helpful Variable Functions ==
*NVAR
+
*'''variable'''/G (creates a global variable)
*NVAR_exists
+
*'''NVAR''' and '''NVAR_exists'''
  
 
= Functions =
 
= Functions =
 
== The Local Procedure File ==
 
== The Local Procedure File ==
 +
The local procedure file exists only in the experiment that it's in.  None of these functions can be read by other experiments.  Functions you want to share between experiments should be stored in an Igor Procedure File (.ipf).
 +
 +
Access the local procedure file by
 +
* ctrl+m
 +
** ''Windows -> Procedure Window -> Procedure Window''
 +
 
== Igor Procedure Files (.ipf) ==
 
== Igor Procedure Files (.ipf) ==
== Local vs. Global Objects ==
 
  
== Lists ==
+
Igor Procedure Files can be loaded into multiple experiments and easily shared with colleagues.  If you edit and save the .ipf, it will be changed for all the experiments that use that .ipf. 
 +
 
 +
=== Making a new .ipf ===
 +
* ''Windows -> New -> Procedure...''
 +
** This file is local to the experiment it was made in until it is saved as a separate file.
 +
 
 +
 
 +
=== Saving an .ipf as a separate file ===
 +
* With the procedure as the top window, ''File -> Save Procedure As...''
 +
 
 +
 
 +
=== Bringing an ipf to the front in an experiment ===
 +
* '' Windows -> Procedure Windows ->'' and choose your .ipf.
 +
 
 +
== Local vs. Global Objects and Constants ==
 +
 
 +
* '''Local''' objects only exist inside a function and are destroyed automatically when the function ends. 
 +
** This is the normal behavior for '''strings''' and '''variables''' inside of functions in Igor. 
 +
** Local objects can never be viewed in the data browser.
 +
 
 +
* '''Global''' variables exist once they are created and must actively be destroyed (killed). 
 +
** '''Waves''' are always global in Igor, whether created in a function or not. 
 +
** '''Strings''' and '''variables''' can be made global by declaring them as such ('''string/G''') in a function or from the command line.
 +
*** It is usually better ''not'' to make strings and variables global unless you need a permanent (or update-able) record of a value.
 +
 
 +
=== Accessing Global Objects in a Function ===
 +
To access an existing global object (i.e., one that is not created in the current function), you must fetch it using it's path in the data browser.
 +
*** Get ''waves'' by '''wave ThisWave = root:ThisGlobalWave'''. 
 +
*** Get ''strings'' by ''SVAR ThisString = root:ThisGlobalString'''.
 +
*** Get ''variables'' by ''NVAR ThisVariable = root:ThisGlobalVariable''.
 +
*** Note that in each of these cases the actual name of the object is on the right side of the = and the  local name in the function is on the left side of the = .
 +
 
 +
* '''Constants''' may be declared in a procedure file and are global for the entire experiment.
 +
** It is good style to name all constants in all capital letters at the top of the procedure file.
 +
** Note that for values that are actually constants (e.g., gravity, Plank's constant, the speed of light) it is safer to declare these as constants because you can't accidentally change their values in a function.
 +
 
 +
== "Controls" in Functions ==
 +
 
 +
=== if / elseif / else / endif ===
 +
''if'' is a conditional statement that must evaluate to "true" for the commands inside the if statement to be executed.
 +
 
 +
Here is a simple case:
 +
 
 +
:if (''conditional test'')
 +
:: things to do
 +
:endif
 +
 
 +
The ''conditional statement'' is usually a comparison between the thing you want to test (often a string or variable) and some limit.  Some examples are
 +
: if(printFlag == 1)
 +
: if(speed > 55) // miles per hour
 +
 
 +
==== Comparison operators for Numbers ====
 +
{|
 +
|==
 +
|
 +
|Equal
 +
|-
 +
|!=
 +
|
 +
|Not Equal
 +
|-
 +
|<=
 +
|
 +
|Less than or equal to
 +
|-
 +
|<
 +
|
 +
|Less than
 +
|-
 +
|>
 +
|
 +
|Greater than
 +
|-
 +
|<=
 +
|
 +
|Greater than or equal to
 +
|}
 +
 
 +
==== Comparisons for Strings ====
 +
 
 +
Special functions are needed to make comparisons for strings (i.e., ''"test" == "test"'' won't work.)  Commonly-used helpful functions include:
 +
* '''stringmatch'''
 +
* '''strlen'''
 +
* '''strsearch'''
 +
 
 +
==== Making multiple conditional tests in the same test ====
 +
 
 +
You can test multiple conditions at once using logical operators
 +
: '''&&''' and
 +
: '''||''' or
 +
 
 +
For example
 +
: ''if(speedLimit == 55 && speed > 55)''
 +
:: '' print "You might get a ticket."''
 +
: ''endif
 +
 
 +
==== Making multiple conditional tests ====
 +
 
 +
Here is an example of making multiple conditional tests:
 +
 
 +
: if(test1)
 +
:: test1 commands
 +
: elseif(test2)
 +
:: test2 commands
 +
: else
 +
:: other commands
 +
: endif
 +
 
 +
Notes:
 +
 
 +
* Once any statement is true and ''commands'' are executed, none of the other conditions are tested!
 +
* "elseif" and "else" are not required in a set of if statements, so if the first condition isn't true, you can do nothing.
 +
* The "Switch" statement can do this as well, especially if you have many options, but the "if" part must be exact matches.  Read the help about "switch" for more info.
 +
 
 +
=== for / endfor ===
 +
 
 +
== Reporting Results from Functions ==
 +
There are three main ways to get the results of a function.  Each is useful for different problems, as described below.
 +
 
 +
=== Print results to Command Window History ===
 +
 
 +
The Igor function '''print''' can be used to print results (text or numbers) to the Command Window History.  Note that these results are not stored anywhere else for later retrieval, so there is no permanent object in a DataFolder that saves this output.
 +
 
 +
==== Helpful print functions ====
 +
* '''print''' ''string''
 +
** The ''string'' can be a combination of text and values from variables, e.g.,
 +
::: '''print''' "The equation of the line is y=", m, "x+", b
 +
:: Note that in this formation, spaces are inserted before and after the values for m and b.  The same output without those spaces can be printed by
 +
::: '''print''' "The equation of the line is y=" + '''num2str'''(m) + "x+" + '''num2str'''(b)
 +
* '''printf''' ''string''
 +
** '''printf''' allows more control of the formatting of a string and values.
 +
 
 +
=== Return one (and only one) value ===
 +
 
 +
The Igor function '''return''' sends one (and only one) value out of a function.  After the function executes this line, the function ends and no further lines are executed. 
 +
 
 +
This is a good way to send a scalar value to another function or to the command line.  You can then store this value in a more permanent wave.  If you call a function that returns a value from the command line, no output is automatically reported.  You must assign the value to a variable, e.g.
 +
: variable myResult = ReturningFunction(x)
 +
or tell Igor to print the value to the command window history, e.g.,
 +
: print ReturningFunction(x)
 +
 
 +
To send results with many values from a function, you have to [[#Store values in a wave | store them in a wave]].
 +
 
 +
==== The return function ====
 +
* '''return'''(''expression'')
 +
** Note that ''expression'' can be as simple as a variable, e.g.
 +
:: '''return'''(x)
 +
: or can be a mathematical equation, e.g.
 +
:: '''return'''(delta_position/delta_time)
 +
 
 +
=== Store values in a wave ===
 +
Since waves are global, you can create a wave inside a function and its values will be stored after the function exits.  See [[#Waves|Waves]] and [[#Accessing Global Objects in a Function| Accessing Global Objects in a Function]]
 +
 
 +
= The Debugger =
 +
The debugger is a great tool for examining what is happening to the values of strings, variables, and waves at every step of a function.
 +
 
 +
== Enable the Debugger ==
 +
# You need to be in a procedure window.  To get to the local procedure window, press ctrl+m.
 +
# Choose ''Procedure -> Enable Debugger''. 
 +
#* Your procedure window now has a grey bar on the left.  You can click in this bar to make a red dot, or "stop".  When you call the procedure and the execution gets to the line with the dot, the debugger will start.
 +
 
 +
== In the Debugger ==
 +
* The top center box shows strings, variables, and waves used by the procedure.  To see all objects used by the current function, choose "local and global variables" from the pulldown above this window.
 +
* If you double-click on a wave in the top center box, the values in the wave will be shown in the top right box.
 +
* The function is shown in the lower box.  The yellow arrow points to the ''next line'' that will be executed.
 +
* The 5 buttons at the upper left of the debugger window control the operation in the debugger window.
 +
** Red with white X: Stop the debugger (sometimes execution continues)
 +
** Yellow arrow: Execute the next line (equivalent of pressing return)
 +
** Blue arrow down: For lines that call another function, enter that function
 +
** Blue arrow right: Return to the function that called the current function
 +
** Green arrow: Continue to the next stop or end of all functions
 +
 
 +
== Debug on Error ==
 +
# You need to be in a procedure window.  To get to the local procedure window, press ctrl+m.
 +
# The debugger must already be [[#Enable the Debugger | enabled]].
 +
# Choose ''Procedure -> Debug on Error''.
 +
Now when you execute any function and Igor encounters an error, the debugger will start and the yellow arrow will point to the line '''after''' the one where the error occurred.  The error is displayed above the list of objects in the top center box.
 +
 
 +
= Miscellaneous Tips and Tricks =
 +
* To skip the "Close Window" dialog that asks if you want to save the window (Tables, Graphs, Panels), hold "Alt" on a PC ("ctrl" on a Mac) while you click the Close icon in the window.
 +
* You can move the columns in a table by holding "Alt" and clicking and dragging a column to a new location.
 +
* The Graph Browser (''Misc -> Graph Browser'') can help keep track of lots of graphs in one experiment.  There are two drawbacks:
 +
*# If you minimize a graph, the Graph Browser shows a minimized version, which can make it hard to identify the graph you're looking for.  Instead of minimizing graphs, you can "hide" them from the graph browser and still see the full graph in the browser.
 +
*# If you hide graphs, there's no minimized version you can click on to find the graph again.  You must retrieve it from the Graph Browser or from ''Windows -> Graphs ->'' and the graph name and waves plotted in the graph.
 +
* When using cursors in a graph, you can press shift+arrow to move 10 points at once.

Latest revision as of 15:25, 17 September 2019

This page is intended to be a resource for the beginning and intermediate Igor user to quickly find help and tips about common tasks in Igor. Much of the information on this page is taken from the Igor "Getting Started" Introduction and Guided Tour, but is organized by topic so that the information is easy to find. Users of this page should also search (ctrl+f) for terms in case what they're looking for isn't found in the topic they expect. A shorcut to this page is http://tinyurl.com/Igor-quick

This page was started by Ingrid Ulbrich.

Contents

Common Keyboard Shortcuts

  • CTRL + J --> command window
    • CTRL + K --> clears command line
  • CTRL + M --> brings the procedure window to the front
  • CTRL + T --> in a graph or panel, enables or disables tools
  • CTRL + I --> in a graph, enables cursors ("info") (Graph -> Show Info)
  • CTRL + Y --> in a graph or table, rename window
  • CTRL + A --> in a table or in the command window: select all
    • --> in a graph: autoscale axes Graph -> Autoscale Axes
  • Common Windows Commands
    • CTRL + S --> save experiment
    • CTRL + C, CTRL + X, CTRL + V --> copy, cut, paste
    • CTRL + F, CTRL + G --> find, find again (with shift, go the opposite direction)
    • CTRL + R --> search and replace
    • CTRL + P --> print
    • CTRL + Z --> undo (only one action before Igor 7)
    • CTRL + N --> new experiment

Waves

Waves are vectors (arrays) in which data is stored. Point number counts from 0 (i.e., MyWave[0] is the first element of the wave).

Waves have inherent x values that are by default equal to the point number. If you display a wave, it is automatically plotted versus the x value (0, 1, 2, etc.). It is possible to change the inherent wave scaling (see setScale), or you can plot a y-wave versus an x-wave.

Waves are global and exist until you kill them.

Helpful Wave Functions

  • make /O /N=points
    • Data -> Make Waves...
  • duplicate /O
    • Data -> Duplicate Waves...
  • rename
    • Data -> Rename
    • when the wave is in a table, right-click and choose Reanme
  • setScale [/I/P] dim, num1, num2
    • You can change the inherent values, but not the data values
    • /P: num1 is start value, num2 is delta value
    • /I: num1 is start value, num2 is last value
    • Data -> Change Wave Scaling...
  • killwaves
    • Data -> Kill Waves...

Putting Data in Waves

Typing in a Table

  1. First you need to view the wave in a table.
    • If the wave exists
      • double-click on it in the Data Browser to view it in a table
      • single-click on it in the Data Browser, then right click and select "Edit"
      • from the pulldown menus, choose Window -> New Table and select the wave(s) from the dialog window
    • If the wave doesn't exist
      • make the wave from the command line
      • Make a new table (from the pulldown menus, choose Window -> New Table and don't choose any existing waves). You can rename the waves later.
  2. Now you can type values directly into the table
    • Note that you are editing the only copy of the wave.
    • Note that Igor can only undo 1 action (it doesn't remember more than 1 action).
    • Note that if you paste into the table, you might insert points instead of overwriting existing data.

As a list of values, in the command line

  • myWave = {12, 24, 36}

Waves in Equations

You can treat a wave as a variable name in equations and assignments are made on a point-to-point (point 0, 1, etc.) basis.

For example, if you have

 make/N=10 x_wave = x  

you can make a wave of a line with slope 3 and intercept 4 by

 make/N=10 y_wave = 3*x_wave + 4

then

 y_wave[0] = 3*x_wave[0] + 4
 y_wave[1] = 3*x_wave[1] + 4
 etc.

Loading Data

From Igor Text Files (.itx)

  • Double-click on the file icon on your computer. Waves will be loaded into the current DataFolder
  • Data -> Load Waves -> Load Igor Text...' and choose the appropriate file

From non-Igor Text Files

  • Data -> Load Waves -> ' and choose to load an appropriate file type

From Excel Files

Graphs

Helpful Graph Functions

  • display
    • Windows -> New Graph
    • From the Data Browser, single-click on a wave then right-click and choose "Display" (can't choose a "vs" wave)
  • appendToGraph
  • legend
  • ModifyGraph


Modifying Trace Appearance

  1. Getting to the window
    • Double-click on a trace
    • Right-click on a graph and choose "Modify (tracename)..."
    • Graph -> Modify Trace Appearance...
  2. Notes and Tricks
    • You can change several traces at once by selecting multiple waves (ctrl+click).
    • "Offset" lets you do additive offsets (x and or y) and multiplicative scaling (x and or y)
    • "Set as f(z)..." lets you set color, marker type, and marker size by any other wave of appropriate length (e.g., color by time, make marker size proportional to value)
    • "Hide Trace" makes the selected trace not visible, but does not remove the associated axis.
      • If the hidden trace had the highest or lowest value and controlled the axis range, the axis range will be reset unless "Autoscale" is checked.
      • This can be useful if you want to show a graph in a presentation where you show versions with more traces in each view. This way you can make all the versions from the same graph.

Reorder Traces

  1. Getting to the window
    • Right-click in the margin of the graph
    • Choose "Reorder Traces..."
  2. Changing the order
    • Drag and drop waves to change the order.
    • Waves are drawn in the plot starting with the first trace (this will be furthest back visually) and ending with the last trace (on top).

Modifying Axes

  1. Getting to the window
    • Double-click on an axis (look for vertical or horizontal double-arrow cursor)
    • Graph -> Modify Axis
  2. Notes and Tricks
    • You can make selections to any axis (or multiple axes at the same time) from the pulldown menu at the upper left of the window.

Adding Text

Legend

  • legend produces the default legend in the top graph
  • Graph -> Add Annotation..., change the Annotation type in the upper left corner to Legend
  • Right-click in the graph and choose "Add Annotation...", change the Annotation type in the upper left corner to Legend
  • Edit an existing legend by double-clicking on it.

Text box

  • Graph -> Add Annotation..., change the Annotation type in the upper left corner to TextBox
  • Right-click in the graph and choose "Add Annotation...", change the Annotation type in the upper left corner to TextBox
  • Edit an existing text box by double-clicking on it.

Tag (Text that is associated with a point in a wave)

  • Graph -> Add Annotation..., change the Annotation type in the upper left corner to TextBox
  • Right-click in the graph and choose "Add Annotation...", change the Annotation type in the upper left corner to TextBox
  • Edit an existing text box by double-clicking on it.

"Drawn" text (less interactive than a text box)

  1. Get to the "Tools" by pressing ctrl+t (Graph -> Show Tools) when the top window is your graph. A set of buttons will appear to the left of your graph.
  2. Choose the "T..." icon and click in the graph where you want the text to be.
  3. Insert your text in the dialog box. Note that you can control the location and formatting of the text here.
  4. Press the top button on the "Tools" to return to normal graph interactions or press ctrl+t to close the "Tools" and return to normal graph interactions.
  5. Notes and Tips
    • After closing the dialog, you must click the arrow icon to move your text.
    • This text can only be moved or changed when "Tools" are available.
    • When "Tools" are enabled (the long list of buttons is showing) you cannot copy a graph (for pasting into a Notebook or other programs). Close the tools (ctrl+t) or click the top button of the toolbar to allow copying.


Adding Straight Lines

With Traces

  • Create a 2-point wave with points = 0, 1
  • Append this trace to the graph and scale it using multiplicative offset (same x-,y-scaling --> 1:1 line; different x-, y-scaling for different slopes)

Drawing Fixed Lines

  • Enable drawing tools by pressing ctrl+t (Graph -> Show Tools).
  • Select the line tool and draw a line.
  • Select the arrow tool and double-click on the line.
  • To make a fixed-value line, set the Coordinate System (upper left pull-down menus) to axes (e.g., "Axis Bottom", "Axis Left")
  • Set the coordinates in the bottom of the dialog box to the axis values for the line. Note that (X0, Y0) is the point where you started the line.

Using Cursors

  1. Press ctrl+i or Graph -> Show info
  2. Drag the cursor icons onto points on the graph
    • Note that the cursors attach only to points in a wave, not line segments
    • You can change the wave that a cursor is on by right-clicking on the wave name and choosing a different name
  3. Wave information is displayed in the bar.
  4. Move the cursors by pressing right and left arrow keys or by moving the vertical bar between the wave names and the point information.
    • "Highlighted" (dark) markers next to the wave name indicate that the cursor will move; open markers indicate that the cursor will not move.
  5. Tips and Tricks
    • Note that point may not equal x value, depending on how your wave is plotted.
    • You can get up to 10 cursors, but you can only see the info from two cursors at a time. Right-click over the names of the waves for the cursors and select "Show Cursor Pair" for a new pair of cursors.

Saving Graphs

Graph Macro

  • ctrl+y. To save the macro choose a name for the macro and check the box to save or update the graph macro. You can give the graph a window title (optional).
    • close the graph and choose "Save"
  • A macro with the name you selected is created in the local procedure window (ctrl+m)
  • This is a handy way to get the code to produce a graph when you want to create a function that makes this graph

Graph Style Macro

  • ctrl+y

Save Graph as its own Experiment

  • File -> Save Graph Copy...

Strings

Helpful String Functions

  • string/G (creates a global string)
  • num2str and str2num
  • stringmatch
  • strlen
  • strsearch
  • SVAR and SVAR_exists

Variables

Helpful Variable Functions

  • variable/G (creates a global variable)
  • NVAR and NVAR_exists

Functions

The Local Procedure File

The local procedure file exists only in the experiment that it's in. None of these functions can be read by other experiments. Functions you want to share between experiments should be stored in an Igor Procedure File (.ipf).

Access the local procedure file by

  • ctrl+m
    • Windows -> Procedure Window -> Procedure Window

Igor Procedure Files (.ipf)

Igor Procedure Files can be loaded into multiple experiments and easily shared with colleagues. If you edit and save the .ipf, it will be changed for all the experiments that use that .ipf.

Making a new .ipf

  • Windows -> New -> Procedure...
    • This file is local to the experiment it was made in until it is saved as a separate file.


Saving an .ipf as a separate file

  • With the procedure as the top window, File -> Save Procedure As...


Bringing an ipf to the front in an experiment

  • Windows -> Procedure Windows -> and choose your .ipf.

Local vs. Global Objects and Constants

  • Local objects only exist inside a function and are destroyed automatically when the function ends.
    • This is the normal behavior for strings and variables inside of functions in Igor.
    • Local objects can never be viewed in the data browser.
  • Global variables exist once they are created and must actively be destroyed (killed).
    • Waves are always global in Igor, whether created in a function or not.
    • Strings and variables can be made global by declaring them as such (string/G) in a function or from the command line.
      • It is usually better not to make strings and variables global unless you need a permanent (or update-able) record of a value.

Accessing Global Objects in a Function

To access an existing global object (i.e., one that is not created in the current function), you must fetch it using it's path in the data browser.

      • Get waves by wave ThisWave = root:ThisGlobalWave.
      • Get strings by SVAR ThisString = root:ThisGlobalString'.
      • Get variables by NVAR ThisVariable = root:ThisGlobalVariable.
      • Note that in each of these cases the actual name of the object is on the right side of the = and the local name in the function is on the left side of the = .
  • Constants may be declared in a procedure file and are global for the entire experiment.
    • It is good style to name all constants in all capital letters at the top of the procedure file.
    • Note that for values that are actually constants (e.g., gravity, Plank's constant, the speed of light) it is safer to declare these as constants because you can't accidentally change their values in a function.

"Controls" in Functions

if / elseif / else / endif

if is a conditional statement that must evaluate to "true" for the commands inside the if statement to be executed.

Here is a simple case:

if (conditional test)
things to do
endif

The conditional statement is usually a comparison between the thing you want to test (often a string or variable) and some limit. Some examples are

if(printFlag == 1)
if(speed > 55) // miles per hour

Comparison operators for Numbers

== Equal
!= Not Equal
<= Less than or equal to
< Less than
> Greater than
<= Greater than or equal to

Comparisons for Strings

Special functions are needed to make comparisons for strings (i.e., "test" == "test" won't work.) Commonly-used helpful functions include:

  • stringmatch
  • strlen
  • strsearch

Making multiple conditional tests in the same test

You can test multiple conditions at once using logical operators

&& and
|| or

For example

if(speedLimit == 55 && speed > 55)
print "You might get a ticket."
endif

Making multiple conditional tests

Here is an example of making multiple conditional tests:

if(test1)
test1 commands
elseif(test2)
test2 commands
else
other commands
endif

Notes:

  • Once any statement is true and commands are executed, none of the other conditions are tested!
  • "elseif" and "else" are not required in a set of if statements, so if the first condition isn't true, you can do nothing.
  • The "Switch" statement can do this as well, especially if you have many options, but the "if" part must be exact matches. Read the help about "switch" for more info.

for / endfor

Reporting Results from Functions

There are three main ways to get the results of a function. Each is useful for different problems, as described below.

Print results to Command Window History

The Igor function print can be used to print results (text or numbers) to the Command Window History. Note that these results are not stored anywhere else for later retrieval, so there is no permanent object in a DataFolder that saves this output.

Helpful print functions

  • print string
    • The string can be a combination of text and values from variables, e.g.,
print "The equation of the line is y=", m, "x+", b
Note that in this formation, spaces are inserted before and after the values for m and b. The same output without those spaces can be printed by
print "The equation of the line is y=" + num2str(m) + "x+" + num2str(b)
  • printf string
    • printf allows more control of the formatting of a string and values.

Return one (and only one) value

The Igor function return sends one (and only one) value out of a function. After the function executes this line, the function ends and no further lines are executed.

This is a good way to send a scalar value to another function or to the command line. You can then store this value in a more permanent wave. If you call a function that returns a value from the command line, no output is automatically reported. You must assign the value to a variable, e.g.

variable myResult = ReturningFunction(x)

or tell Igor to print the value to the command window history, e.g.,

print ReturningFunction(x)

To send results with many values from a function, you have to store them in a wave.

The return function

  • return(expression)
    • Note that expression can be as simple as a variable, e.g.
return(x)
or can be a mathematical equation, e.g.
return(delta_position/delta_time)

Store values in a wave

Since waves are global, you can create a wave inside a function and its values will be stored after the function exits. See Waves and Accessing Global Objects in a Function

The Debugger

The debugger is a great tool for examining what is happening to the values of strings, variables, and waves at every step of a function.

Enable the Debugger

  1. You need to be in a procedure window. To get to the local procedure window, press ctrl+m.
  2. Choose Procedure -> Enable Debugger.
    • Your procedure window now has a grey bar on the left. You can click in this bar to make a red dot, or "stop". When you call the procedure and the execution gets to the line with the dot, the debugger will start.

In the Debugger

  • The top center box shows strings, variables, and waves used by the procedure. To see all objects used by the current function, choose "local and global variables" from the pulldown above this window.
  • If you double-click on a wave in the top center box, the values in the wave will be shown in the top right box.
  • The function is shown in the lower box. The yellow arrow points to the next line that will be executed.
  • The 5 buttons at the upper left of the debugger window control the operation in the debugger window.
    • Red with white X: Stop the debugger (sometimes execution continues)
    • Yellow arrow: Execute the next line (equivalent of pressing return)
    • Blue arrow down: For lines that call another function, enter that function
    • Blue arrow right: Return to the function that called the current function
    • Green arrow: Continue to the next stop or end of all functions

Debug on Error

  1. You need to be in a procedure window. To get to the local procedure window, press ctrl+m.
  2. The debugger must already be enabled.
  3. Choose Procedure -> Debug on Error.

Now when you execute any function and Igor encounters an error, the debugger will start and the yellow arrow will point to the line after the one where the error occurred. The error is displayed above the list of objects in the top center box.

Miscellaneous Tips and Tricks

  • To skip the "Close Window" dialog that asks if you want to save the window (Tables, Graphs, Panels), hold "Alt" on a PC ("ctrl" on a Mac) while you click the Close icon in the window.
  • You can move the columns in a table by holding "Alt" and clicking and dragging a column to a new location.
  • The Graph Browser (Misc -> Graph Browser) can help keep track of lots of graphs in one experiment. There are two drawbacks:
    1. If you minimize a graph, the Graph Browser shows a minimized version, which can make it hard to identify the graph you're looking for. Instead of minimizing graphs, you can "hide" them from the graph browser and still see the full graph in the browser.
    2. If you hide graphs, there's no minimized version you can click on to find the graph again. You must retrieve it from the Graph Browser or from Windows -> Graphs -> and the graph name and waves plotted in the graph.
  • When using cursors in a graph, you can press shift+arrow to move 10 points at once.