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

doha420du
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.
add this:
Then use newMatrix instead of $NewMatrixName thereafter.
For details, execute:
It would also be a good idea to read the entire Programming help file or the equivalent first three chapters in the PDF manual
January 3, 2017 at 01:23 pm - Permalink
I have tried as you said but it is showing me following error.
January 4, 2017 at 08:24 am - Permalink
January 5, 2017 at 07:13 am - Permalink
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:
So the bottom line is that you need to pass an image name to ModifyImage, not a wave reference, like this:
I created a separate ImageName local variable to make this subtle distinction more evident. You could also do this, which is equivalent:
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:
January 5, 2017 at 07:34 am - Permalink
Till now I am having the same problem... :(
I have attached the matrix by which I am trying...
January 5, 2017 at 02:05 pm - Permalink
Also
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.
Finally, the Redimension call is unnecessary because, after Duplicate, the new matrix will have the same dimensions as the original matrix.
January 5, 2017 at 03:37 pm - Permalink
When I run the function, as an example:
It is showing me the same error like:
To speak the truth I don't understand why it is taking 'string function name'...???
January 7, 2017 at 10:14 am - Permalink
The second parameter is a string and you passed a name (and the name was apparently not the name of a string variable).
--Jim Prouty
Software Engineer, WaveMetrics, Inc.
January 7, 2017 at 11:37 am - Permalink
Thanks...
January 9, 2017 at 09:14 am - Permalink