Changing indexed values in multiple waves
ssmith911
I have 6 waves that are related and are the same length. There are bad points in one of the waves that I wish to turn into nans. Is there an easy way to change points 10 - 20 to nans in each of the waves without looping or typing in 6 lines of code? Ideally i would want to apply the range once and have it change all of the waves. The only way I could see it would be this example:
Wave test1,test2,test3,test4,test5,test6
Test1[10,20]=nan; Test2[10,20]=nan; Test3[10,20]=nan; Test4[10,20]=nan; Test5[10,20]=nan; Test6[10,20]=nan
...but then I would have to change the wave range in each instance.
Any help is appreciated, Thanks.
ssmith
If I understand your desire ... Concatenate the six waves into a matrix (6xN). Set the region matrix[10,20][] = NaN. Split the matrix back to six waves. I think this is three lines of code. :-)
December 5, 2023 at 11:39 am - Permalink
Variable First = 10
Variable Snd = 20
wtest[first, snd] = nan
December 5, 2023 at 12:20 pm - Permalink
You can also create one key wave with zero values where you want to keep the original data and 1 where you want to set nans and then apply MatrixOP with the setNaNs() function to each one of the waves.
December 5, 2023 at 01:52 pm - Permalink
Could you tell us a bit more about your task? You write about six waves, but it also sounds like a more general procedure ('...I would have to change the wave range in each instance'). I think JJ's answer is the shortest code-wise, but you have certain limitations (same length of all waves, and the 'bad points' have to be at the same position). Is there some way to detect 'bad points'? You could write a mini function to automatically clear these points without manual input, for example.
December 5, 2023 at 05:47 pm - Permalink
I do this kind of thing with functions that have more than 6 lines of code :(
function has an optional wave reference wave as parameter; any point removed from target is also removed from waves referenced in waveref wave.
something like this
if (!ParamIsDefault(refs))
for (w : refs)
w = pointisbad(target) ? NaN : w
endfor
endif
target = pointisbad(target) ? NaN : target
end
December 6, 2023 at 01:40 am - Permalink
In reply to If I understand your desire … by jjweimer
I've never done this and I like this approach. What command will separate the waves out of the matrix and back to 6 separate waves?
Thanks a lot for the help.
ssmith
December 12, 2023 at 11:46 am - Permalink
Check out SplitWave or use MatrixOP with the Col() function as many times as necessary.
December 12, 2023 at 03:53 pm - Permalink
Assuming all your test waves have the same size and are one-dimensional:
temp_merged[10,20] = NaN
SplitWave/O/NAME="Test1;Test2;Test3;Test4;Test5;Test6;" temp_merged
KillWaves/Z temp_merged
You can construct the string input for Concatenate and SplitWave dynamically, depending on how many waves you have. You can also go for /FREE instead of the /O flag for Concatenate when you are working inside a function. This would make the KillWaves line unnecessary.
December 12, 2023 at 10:02 pm - Permalink
Perfect!! Thanks a lot. I really appreciate the help. Happy Holidays to everyone!!
ssmith
December 13, 2023 at 07:04 am - Permalink