How to duplicate a wave or matrix by a provided name using function??? [SOLVED...]

 

Hi,
I am new in Igor. I am trying to plot an image after doing an operation of the given matrix.
I have written an function and it works perfectly...where I have a fixed name of the new matrix.

 

Function PlotRelAnisotropyImage()
   
    wave matrix

    Display;DelayUpdate
    AppendImage matrix;DelayUpdate
    ModifyImage matrix ctab= {-6.13085,0.465855,VioletOrangeYellow,1};DelayUpdate
    Label left "Polarizer Angle (Degrees)";DelayUpdate
    Label bottom "Wavelength (nm)";DelayUpdate

    Duplicate matrix, RelAnisotropy

    Variable numRows = DimSize(matrix,0)
    Variable numColumns = DimSize(matrix,1)

    Redimension/N=(numRows,numColumns) RelAnisotropy
   
    Variable i,j,k
    for(i=0; i<numRows; i+=1)
        for (j=0; j<numColumns; j+=1)
            k = (j*5)+90
            if (k>360)
                k = k-360
            else
                k = k
            endif
            RelAnisotropy[i][j] = matrix[i](j*5) - matrix[i](k)
        endfor
    endfor
   
    Display;DelayUpdate
    AppendImage RelAnisotropy;DelayUpdate
    ModifyImage RelAnisotropy ctab= {-4.82601,0.74151,VioletOrangeYellow,1};DelayUpdate
    Label left "Polarizer Angle (Degrees)";DelayUpdate
    Label bottom "Wavelength (nm)";DelayUpdate
End


Now, at time of calling the function, I want to provide the name of the new matrix. How can I do that...???
I have tried in the following way... but getting many errors...

 

Function PlotRelAnisotropyImage(MatrixName, NewMatrixName)
    Wave MatrixName
    String NewMatrixName
   
    Display;DelayUpdate
    AppendImage MatrixName;DelayUpdate
    ModifyImage MatrixName ctab= {-6.13085,0.465855,VioletOrangeYellow,1};DelayUpdate
    Label left "Polarizer Angle (Degrees)";DelayUpdate
    Label bottom "Wavelength (nm)";DelayUpdate

    Duplicate MatrixName, $NewMatrixName
    Variable numRows = DimSize(MatrixName,0)
    Variable numColumns = DimSize(MatrixName,1)

    Redimension/N=(numRows,numColumns) $NewMatrixName
   
    Variable i,j,k
    for(i=0; i<numRows; i+=1)
        for (j=0; j<numColumns; j+=1)
            k = (j*5)+90
            if (k>360)
                k = k-360
            else
                k = k
            endif
            $NewMatrixName[i][j] = MatrixName[i](j*5) - MatrixName[i](k)
        endfor
    endfor

    Display;DelayUpdate
    AppendImage $NewMatrixName;DelayUpdate
    ModifyImage $NewMatrixName ctab= {-4.82601,0.74151,VioletOrangeYellow,1};DelayUpdate
    Label left "Polarizer Angle (Degrees)";DelayUpdate
    Label bottom "Wavelength (nm)"
End



Thanks in advance.

After this:
Duplicate MatrixName, $NewMatrixName


add this:
Wave newMatrix = $NewMatrixName  // Create wave reference for new wave


Then use newMatrix instead of $NewMatrixName thereafter.

For details, execute:
DisplayHelpTopic "Wave References"


It would also be a good idea to read the entire Programming help file or the equivalent first three chapters in the PDF manual
Hi hrodstein,
I have tried as you said but it is showing me following error.
Syntax Error: Got "NewMatrixName" instead of a string variable or string function name.
In your code, after the Duplicate operation and the statement creating the newMatrix wave reference, change all occurrences of $NewMatrixName to newMatrix.
Quote:
Hi hrodstein,
I have tried as you said but it is showing me following error.
Syntax Error: Got "NewMatrixName" instead of a string variable or string function name.


This is because ModifyImage takes an image name, not a wave reference. The reason for this subtle distinction is that you can append the same wave as an image to a given graph multiple times and each image must have a distinct name. This is analogous to the distinction between a trace name and a wave name. You can read about this by executing:
DisplayHelpTopic "Trace Names"


So the bottom line is that you need to pass an image name to ModifyImage, not a wave reference, like this:
Display;DelayUpdate
AppendImage NewMatrix;DelayUpdate
String ImageName = NewMatrixName
ModifyImage $ImageName ctab= {-4.82601,0.74151,VioletOrangeYellow,1};DelayUpdate


I created a separate ImageName local variable to make this subtle distinction more evident. You could also do this, which is equivalent:
ModifyImage $NewMatrixName ctab= {-4.82601,0.74151,VioletOrangeYellow,1};DelayUpdate


One more thing - I removed all of the DelayUpdate calls. They do nothing in a user-defined function during which updates are off by default.

Here is the function with all of the changes:

Function PlotRelAnisotropyImage(MatrixName, NewMatrixName)
    Wave MatrixName
    String NewMatrixName
 
    Display
    AppendImage MatrixName
    ModifyImage MatrixName ctab= {-6.13085,0.465855,VioletOrangeYellow,1}
    Label left "Polarizer Angle (Degrees)"
    Label bottom "Wavelength (nm)"
 
    Duplicate MatrixName, $NewMatrixName
    Wave NewMatrix = $NewMatrixName                 // Create wave reference for new wave
    Variable numRows = DimSize(MatrixName,0)
    Variable numColumns = DimSize(MatrixName,1)
 
    Redimension/N=(numRows,numColumns) NewMatrix
 
    Variable i,j,k
    for(i=0; i<numRows; i+=1)
        for (j=0; j<numColumns; j+=1)
            k = (j*5)+90
            if (k>360)
                k = k-360
            else
                k = k
            endif
            NewMatrix[i][j] = MatrixName[i](j*5) - MatrixName[i](k)
        endfor
    endfor
 
    Display
    AppendImage NewMatrix
    String ImageName = NewMatrixName
    ModifyImage $ImageName ctab= {-4.82601,0.74151,VioletOrangeYellow,1}
    Label left "Polarizer Angle (Degrees)"
    Label bottom "Wavelength (nm)"
End

Hi hrodstein,

Till now I am having the same problem... :(

I have attached the matrix by which I am trying...
matrix.zip (543.41 KB)
There was a similar issue in the first ModifyImage command, at the top of the function, where you were treating a wave reference name (MatrixName) as the name of an image. To understand the difference, execute:

DisplayHelpTopic "Wave References"


Also
DisplayHelpTopic "Trace Names"   // Image names are analogous to trace names


I fixed this the same as I previously fixed the probem with the second ModifyImage command.

For clarity, I changed your "MatrixName" parameter to MatrixRef, to make it clear that it is a reference to a wave, not the name of a wave.

For the same reason, I changed NewMatrix to NewMatrixRef.

I also changed the NewMatrixName parameter to NewMatrixNameStr because it is not the name of a matrix but rather a string variable containing the name to use for the new matrix wave.

Here is the resulting function. I have marked the major changes with *** so you can see where they are.

Function PlotRelAnisotropyImage(MatrixRef, NewMatrixNameStr)
    Wave MatrixRef
    String NewMatrixNameStr
 
    Display
    AppendImage MatrixRef
    String ImageNameStr = NameOfWave(MatrixRef)                         // ***
    ModifyImage $ImageNameStr ctab= {-6.13085,0.465855,VioletOrangeYellow,1}    // ***
    Label left "Polarizer Angle (Degrees)"
    Label bottom "Wavelength (nm)"
 
    Duplicate/O MatrixRef, $NewMatrixNameStr        // *** Added /O
    Wave NewMatrixRef = $NewMatrixNameStr                   // Create wave reference for new wave
    Variable numRows = DimSize(MatrixRef,0)
    Variable numColumns = DimSize(MatrixRef,1)
 
    Redimension/N=(numRows,numColumns) NewMatrixRef
 
    Variable i,j,k
    for(i=0; i<numRows; i+=1)
        for (j=0; j<numColumns; j+=1)
            k = (j*5)+90
            if (k>360)
                k = k-360
            else
                k = k
            endif
            NewMatrixRef[i][j] = MatrixRef[i](j*5) - MatrixRef[i](k)
        endfor
    endfor
 
    Display
    AppendImage NewMatrixRef
    String NewImageNameStr = NameOfWave(NewMatrixRef)
    ModifyImage $NewImageNameStr ctab= {-4.82601,0.74151,VioletOrangeYellow,1}
    Label left "Polarizer Angle (Degrees)"
    Label bottom "Wavelength (nm)"
End


Finally, the Redimension call is unnecessary because, after Duplicate, the new matrix will have the same dimensions as the original matrix.


Hi hrodstein,

When I run the function, as an example:
PlotRelAnisotropyImage(matrix, test_matrix)

It is showing me the same error like:
Syntax Error: Got "test_matrix" instead of a string variable or string function name.

To speak the truth I don't understand why it is taking 'string function name'...???
Use:

PlotRelAnisotropyImage(matrix, "test_matrix")


The second parameter is a string and you passed a name (and the name was apparently not the name of a string variable).

doha420du wrote:
Hi hrodstein,

When I run the function, as an example:
PlotRelAnisotropyImage(matrix, test_matrix)

It is showing me the same error like:
Syntax Error: Got "test_matrix" instead of a string variable or string function name.

To speak the truth I don't understand why it is taking 'string function name'...???


--Jim Prouty
Software Engineer, WaveMetrics, Inc.
JimProuty wrote:
Use:

PlotRelAnisotropyImage(matrix, "test_matrix")


The second parameter is a string and you passed a name (and the name was apparently not the name of a string variable).

doha420du wrote:
Hi hrodstein,

When I run the function, as an example:
PlotRelAnisotropyImage(matrix, test_matrix)

It is showing me the same error like:
Syntax Error: Got "test_matrix" instead of a string variable or string function name.

To speak the truth I don't understand why it is taking 'string function name'...???


--Jim Prouty
Software Engineer, WaveMetrics, Inc.


Thanks...