Variables into new wave

Olav Kiam
Posts: 13
Joined: 2008-10-22
Location: Netherlands

Dear Igor Users,

For the last past days I have been trying to work with Igor Pro, to see if it can replace Origin Pro, which is to cryptic for me (in terms of automating).
So I am new to Igor, and as I was trying to write some procedures all went well, untill... A very simple problem I hope but here it is:

I have loaded 10 waves, each consisting of 10,000 values (electrophysiological recordings, representing Current). I can write the procedure for plotting these against there own x-axis, place cursors (A and B) and, through a while-loop, calculate the mean value between the two cursors. These means are printed into the history-window. The same procedure goes on 10 other waves, representing to Voltage to these currents.

The next thing I can't get to work: I want to plot the mean of Current Wave against the mean of the respective Voltage-wave. From this point on, I can't figure it out. I can create a new wave, but it will contain 128 zeroes, and not my 10 means.

Therefore my question is: how can I put these ten values into a wave? Or is there better way to do this? I need to be doing this a lot, so therefore I would like this to be performed as automated as possible.

Thanks in advance for any help,

Olav


JimProuty's picture
Posts: 281
Joined: 2007-07-19
Location: United States

This sounds simple enough. If you post your code we can see where you're going wrong.

Software Engineer, WaveMetrics, Inc.


Olav Kiam
Posts: 13
Joined: 2008-10-22
Location: Netherlands

For sure I hope it is something simple! Here is the code (not very well polished yet, but was still scrambling around a bit):

#pragma rtGlobals=1 // Use modern global access method.
#include menus=0
#include

Function CreateGraphs()

String x_as = "Time1"
String framelist = WaveList("Current*",";","")
processWaves(framelist, x_as)

end

//##########################################
Function processWaves(list, xaxis)

String list // A semicolon-separated list.
String xaxis
String theWave
String newWaveName = "MeansBetweenCursors"
Variable meanBC
Variable index=0

do // Get the next wave name
theWave = StringFromList(index, list)

if (strlen(theWave) == 0)
break // Ran out of waves
endif
if (index == 0) // Is this the first wave?
Display $theWave vs $xaxis
else
AppendToGraph $theWave vs $xaxis
endif

placeCursors(theWave)

meanBC = meanBetweenCursors(theWave)
print meanBC // Here I would like the means to be put in a list
// or sent to the wave that is created in the next
// statement.

newWave(newWaveName, meanBC)

index += 1
while (1) // Loop until break above
End

//##########################################

Function placeCursors(theWave)

String theWave

Cursor/P A, $theWave, 5394
Cursor/P B, $theWave, 5494

end

//##########################################

Function meanBetweenCursors(theWave)

string theWave
Variable x1= pcsr(A)
Variable x2= pcsr(B)

Variable meanBC = mean($theWave,x1,x2)

return meanBC
end

//##########################################
// This part is where I get stuck.
Function newWave(newWaveName, values)

Wave $newWaveName

Make/O newWaveName{values}

end


JimProuty's picture
Posts: 281
Joined: 2007-07-19
Location: United States

Try this:

//##########################################
Function processWavesFixed(list, xaxis)
	String list // A semicolon-separated list.
	String xaxis
 
	String theWave
	Variable meanBC
	Variable index=0
 
	Variable numWaves= ItemsInList(list)
	Make/O/N=(numWaves) MeansBetweenCursors
 
	do // Get the next wave name
		theWave = StringFromList(index, list)
 
		if (strlen(theWave) == 0)
			break // Ran out of waves
		endif
		if (index == 0) // Is this the first wave?
			Display $theWave vs $xaxis
		else
			AppendToGraph $theWave vs $xaxis
		endif
 
		placeCursors(theWave)
 
		meanBC = meanBetweenCursors(theWave)
		// Here I would like the means to be put in a list
		// or sent to the wave that is created in the next
		// statement.
		MeansBetweenCursors[index]= meanBC
 
		index += 1
	while (1) // Loop until break above
End


Posts: 563
Joined: 2007-03-01
Location: United States

Here is your one function that works as I believe you wish it to:

Function processWaves(list, xaxis)
 
	String list // A semicolon-separated list.
	String xaxis
	String theWave
	String newWaveName = "MeansBetweenCursors"
	Variable meanBC
	Variable index=0
 
	Variable numWaves = ItemsInList(list, ";")
	Make/N=(numWaves) meanValuesWave
 
	do // Get the next wave name
		theWave = StringFromList(index, list)
 
		if (strlen(theWave) == 0)
			break // Ran out of waves
		endif
		if (index == 0) // Is this the first wave?
			Display $theWave vs $xaxis
		else
			AppendToGraph $theWave vs $xaxis
		endif
 
		placeCursors(theWave)
 
		// Here I would like the means to be put in a list
		// or sent to the wave that is created in the next
		// statement.
		meanValuesWave[index] = meanBetweenCursors(theWave)
		print meanValuesWave[index] 
 
		index += 1
	while (1) // Loop until break above
End

And, just for fun, here's how I would have written the code you posted above. Note that, you might have simplified this to some degree such that several of the functions you use might actually be necessary if they would normally do something else. Also, there might be even better ways to do this, depending on what exactly it is that you are trying to do. I haven't tested the code below, but I think it will do the same as your code is currently doing, though it won't actually place the cursors on the graph.

Function CreateGraphs()
 
	String x_as = "Time1"
	String framelist = WaveList("Current*",";","")
	processWaves(framelist, x_as, 5394, 5494)
 
end
 
//##########################################
Function processWaves(list, xaxis, firstPoint, lastPoint)
	String list // A semicolon-separated list.
	String xaxis
	Variable firstPoint
	Variable lastPoint
 
	String theWaveName
	String newWaveName = "MeansBetweenCursors"
	Variable meanBC
	Variable index=0
 
	Variable numWaves = ItemsInList(list, ";")
	Make/N=(numWaves) $(newWaveName)
	WAVE meanValuesWave = $(newWaveName)
 
	For (index = 0; index<numWaves; index += 1)
		theWaveName = StringFromList(index, list)
		WAVE thisWave = $(theWaveName)
 
		if (index == 0) // Is this the first wave?
			Display $theWaveName vs $xaxis
		else
			AppendToGraph $theWaveName vs $xaxis
		endif
 
		// Here I would like the means to be put in a list
		// or sent to the wave that is created in the next
		// statement.
		meanValuesWave[index] = mean(thisWave,pnt2x(thisWave, firstPoint), pnt2x(thisWave, lastPoint))
		print meanValuesWave[index] 
 
		index += 1
	EndFor
End


Olav Kiam
Posts: 13
Joined: 2008-10-22
Location: Netherlands

Great!

Just what I was looking for! I see now how to create a wave from my variables. This really helps me a lot, since this will be something I'll be doing a lot.
Thanks for the the help!

Olav Kiam


Back to top