Wave Arithmetic with String reference waves($)

Hello,

I am new to igor pro and trying to code a loop where I can create a batch of new waves from the difference of 2 waves. The target waves are based on the cursors on another graph. I tried using MatrixOP and used string list as a wave reference for the new wave names and a string list wave reference for one of the waves in the matrix expression. In my code, MatrixOP doesnt recognize the string list as the reference wave and therefore get an error message. Could any please offer any suggestions? 

Many thanks

 

static function VoltammogramsMatrix2()
//make baseline wave
    string theWaveList=WaveList("Cal*", ";", "DIMS:1")
    string theWaveNamebase
    string baseLineList= ""
    variable q=0
    variable a=pcsr(A, "Timec")
    variable b=pcsr(B, "Timec")
    for(q=a; q<b+1; q+=1)
        theWaveNamebase=StringFromList(q, theWaveList)
        baseLineList=AddListItem(theWaveNamebase, baseLineList, ";")
    endfor
    fWaveAverage(baseLineList, "", 0,0, "baseline", "")
//make the stimulus waves  list
    variable firstw=pcsr(C, "Timec")
    variable lastw=pcsr(D, "Timec")
    variable w=0   
    string stimWaveList= ""
    for(w=firstw; w<lastw+1; w+=1)
        theWaveNameBase=StringFromList(w, theWaveList)
        stimWaveList=AddListItem(theWaveNamebase, stimWaveList, ";")
        wave stim=$stimWaveList
        print stimWaveList
    endfor
//make the diff name list
    string diffList= ""
    for(w=firstw; w<lastw+1; w+=1)
        string name=StringFromList(w, theWaveList)+"_diff"
        diffList=AddListItem(name, diffList, ";")
        wave diff=$diffLIst
        print diffList
    endfor
//make diff waves  
    variable num=(ItemsInList(diffList, ";")
    print num
    for(w=0; w<(num+1); w+=1)
        wave diff=$StringFromList(w, diffList)
        wave stim=$StringFromList(w, stimWaveList)
        wave base=baseline
        MatrixOP /O /S diff=stim-base
    endfor
end    

 

static function VoltammogramsMatrix2() //make baseline wave string theWaveList=WaveList("Cal*", ";", "DIMS:1") string theWaveNamebase string baseLineList= "" variable q=0 variable a=pcsr(A, "Timec") variable b=pcsr(B, "Timec") for(q=a; q

I'm not sure what this refers to:

wave base=baseline

Execute this for information about wave references:

DisplayHelpTopic "Wave References"

Execute this for information about debugging wave references:

DisplayHelpTopic "Debugging on Error"

If you can create a minimal, self-contained example that anyone can execute, you will likely get a quick and accurate answer.

 

In reply to by hrodstein

@hrodstein thanks for the suggestions on the display topics. Had previously looked at wave references one but will look at it again to see if it will shed some light on my problem. In the meantime Ive compiled a minimal self contained example for others to help if they can: 

#pragma moduleName=WaveArithmatic

static function diffwave()
    //////waves for this example
    make /O /N=20 baseline=enoise(2,1)
    variable i=0
   
    for(i=0; i<11; i+=1)
        string theWaveList="stim"+num2str(i)
        make /O /N=20 $theWaveList=enoise(4,1)
    endfor
    /////end of waves for this example
    theWaveList=WaveList("stim*", ";", "DIMS:1")
    string theWaveNameBase
    string stimWaveList= ""
    for(i=0; i<11; i+=1)
        theWaveNameBase=StringFromList(i, theWaveList)
        stimWaveList=AddListItem(theWaveNameBase, stimWaveList, ";")
    endfor
    print stimWaveList //to check validity of list only
    string diffList= ""
    for(i=0; i<11; i+=1)
        string name=StringFromList(i, theWaveList)+"_diff"
        diffList=AddListItem(name, diffList, ";")
    endfor
    print diffList //to check validity of list only    
    for(i=0; i<11; i+=1)
        wave diff=$StringFromList(i, diffList)
        wave stim=$StringFromList(i, stimWaveList)
        wave base=baseline
        MatrixOP /O /S diff=stim-base
    endfor 
end

This code follows the same principle as the previously posted code for my data analysis. I hope this helps and everyone feel free to provide input. Thanks!

I think the following code does what you want:

static function diffwave()
    //////waves for this example
    make /O /N=20 baseline=enoise(2,1)
    variable i=0
   
    for(i=0; i<11; i+=1)
        string theWaveList="stim"+num2str(i)
        make /O /N=20 $theWaveList=enoise(4,1)
    endfor
    /////end of waves for this example
    theWaveList=WaveList("stim*", ";", "DIMS:1")
    string theWaveNameBase
    string stimWaveList= ""
    for(i=0; i<11; i+=1)
        theWaveNameBase=StringFromList(i, theWaveList)
        stimWaveList=AddListItem(theWaveNameBase, stimWaveList, ";")
    endfor
    print stimWaveList //to check validity of list only
    string diffList= ""
    for(i=0; i<11; i+=1)
        string name=StringFromList(i, theWaveList)+"_diff"
        diffList=AddListItem(name, diffList, ";")
    endfor
    print diffList //to check validity of list only    
    for(i=0; i<11; i+=1)
        wave stim=$StringFromList(i, stimWaveList)
        wave base=baseline
        MatrixOP /O /S $StringFromList(i, diffList)=stim-base
    endfor  
end

Igor was giving an error on this statement:

 wave diff=$StringFromList(i, diffList)

At the time the code executes, there is no wave whose name is the result of evaluating the expression on the right hand side (eg. no stim#_diff wave. Instead, you need to use the $ operator in the MatrixOp expression to provide a name for the output wave.

Forum

Support

Gallery

Igor Pro 9

Learn More

Igor XOP Toolkit

Learn More

Igor NIDAQ Tools MX

Learn More