01-10-2012 02:34 PM
Hi,
Just stumbled on this and thought I'd see if anyone could offer a more efficient solution?
I'd like to remove the negative values from an array (or values below any specified value?) Ive had a crack but maybe theres a better way?
Any thoughts would be appreciated.
01-10-2012 02:46 PM
01-10-2012 02:54 PM
Just to be different (if you really want to replace with NaN instead of removing the negative elements)
01-10-2012 03:04 PM - edited 01-10-2012 03:05 PM
SDmanc wrote:I'd like to remove the negative values from an array (or values below any specified value?) Ive had a crack but maybe theres a better way?
As others have already said, your code does not "remove" anything, it just replaces certain values with NaN, keeping the array size constant. This is sufficient for waveform graphs where NaN's are not displayed.
Here's another cute solution 😄
If you really want to remove the negatives, shrinking the array accordingly, you need a little more code, of course.
01-10-2012 03:14 PM
I like that one too, fits nicely with the threshold.
01-10-2012 03:56 PM
Hi,
Wow, thanks for the rapid responses.
What I want to do is replace the negative (or indeed above any set threshold) with a NaN so that when the waveform is plotted I can fit/filter/signal process etc.
But the potential issue is that I have to do this fairly rapidly as the data is from a DAQ card so the most efficient way is what I'm after. I'll try some the ways you all have suggested and I'll let you know which is best.
Thanks all, I really appreciate the time you've spent.
01-10-2012 04:05 PM
SDmanc wrote:What I want to do is replace the negative (or indeed above any set threshold) with a NaN so that when the waveform is plotted I can fit/filter/signal process etc.
Be aware that most fit/filter/process functions probably don't really like NaN and you might get very unexpected results.
The NaN method is mostly cosmetic and suitable for plotting, but not much more. 😉