
Duplicate wave with arithmetic options
Greetings Forum,
I'm kind of new to programming with igor. I want to duplicate "wave k" to create "wave j" such that each point in "wave j" is subtracted from previous point in "wave k", something like this (image):
It doesn't have to be a duplicate, I think one can define function to make this, any ideas how?
Thanks in advance.


Forum

Support

Gallery
Igor Pro 10
Learn More
Igor XOP Toolkit
Learn More
Igor NIDAQ Tools MX
Learn More
This can be easily done by the wave assignment in Igor Pro. You can see a demonstration by executing the above.
Here, p is the bin number of the waves, aligning the bin 1 of LHS to bin 1 of RHS, so and so forth. An assignment of Subtracted[] = Original[p] will make a bin-to-bin copy from Original to Subtracted. Now with the above, I am assigning them while doing the subtraction.
February 20, 2019 at 01:43 pm - Permalink
This, of course, uses literal wave names in the commands. If you are using this inside a function, it is likely that the names should be variable. That adds some complexity.
For information about what all those square brackets and p's are doing: DisplayHelpTopic "Waveform Arithmetic and Assignment"
I would discourage wave names that are one character as they aren't very descriptive. And i, j, k are frequently used in programming as the index variables in loops.
February 20, 2019 at 01:49 pm - Permalink
In reply to •make/o/n=20 Original=p^2 … by Sandbo
@Sandbo- be careful with point 0!
February 20, 2019 at 01:50 pm - Permalink
In reply to @Sandbo- be careful with… by johnweeks
Thanks for pointing that out lol
At first I also wondered what will happen when it goes below zero, but somehow it worked. Maybe under some situation it will complain.
February 20, 2019 at 02:05 pm - Permalink
In Igor 8 I think the "index out of bounds" error is always turned on. In some previous version, it was only on if you added
#pragma rtErrors=3
at the top of your procedure file. In old versions, the point numbers were simply clipped to the range [0, npoints), leading to some strange and hard to find bugs.
February 20, 2019 at 02:12 pm - Permalink
Before reading the comments I was trying to figure out by myself, and came up with something like this:
but the issue was the first element in J has to be 0 .....
and then with the help of my friend, wrote a do while loop as such:
Thanks a lot for your comments,
February 20, 2019 at 03:38 pm - Permalink
Just as food for thought: You can get rid of the if statement with initializing Jay2 with zero and write things more compact with a for loop.
Btw, your variables Jay1, KayP1, KayM1 and the wave 'Jay' is not used further in your function. Do they have any purpose?
February 25, 2019 at 08:57 pm - Permalink