Community Tip - You can Bookmark boards, posts or articles that you'd like to access again easily! X
After much hair-pulling and manual debugging, I cannot resolve an issue that is breaking a calculation in my for loop. I have imported a dataset that I want to apply various moving average filters to and output a statistical value on the data (mean, stdev, etc...) My issue is that identical arrays are either working or breaking my loop.
If I specify a manual vector of points, the calculation works. If I have a for loop to create an array of time for my moving average filter based on number of filters and max filter time (s), and multiply by frequency (Hz), I get what seems to be an identical vector. One (the manual) is working, and one (the loop generated) fails, even though the look identical.
Image shown below.
Left side, manual "n_filter" enabled and automatically generated "n_filter" disabled.
Right side, manual "n_filter" disabled and automatically generated "n_filter" enabled.
Solved! Go to Solution.
Obviously the calculated vector contains not the same values as the manually typed in. As we don't see what f.aq and t.MA are and how those values are derived we cannnot tell where the difference is. It might be some decimals because of round off errors it might even be that the calculated vector contains non-real values with a very tiny imaginary part. Without seeing the sheet we cannot tell.
Furthermore you do not even reveal what the error message says! Obviously the call to movavg() fails and if the second argument is not a true integer, this function must fail.
So check the calculated vector if the values are true integers by showing more decimals and apply the "round" function where necessary.
A workaround can be to use
n.pts <-- round(n.filter[i)
in your function instead of just n.pts <-- n.filter[i
Hi,
You should attach the complete file, or only the affected section. Otherwise what can we do? rewrite the program?!?!
Just looking for someone to point out the obvious. Werner picked up on it right away.
Obviously the calculated vector contains not the same values as the manually typed in. As we don't see what f.aq and t.MA are and how those values are derived we cannnot tell where the difference is. It might be some decimals because of round off errors it might even be that the calculated vector contains non-real values with a very tiny imaginary part. Without seeing the sheet we cannot tell.
Furthermore you do not even reveal what the error message says! Obviously the call to movavg() fails and if the second argument is not a true integer, this function must fail.
So check the calculated vector if the values are true integers by showing more decimals and apply the "round" function where necessary.
A workaround can be to use
n.pts <-- round(n.filter[i)
in your function instead of just n.pts <-- n.filter[i
That you Werner! Sometimes you can't see the forest for the trees.
I had checked the value of f_aq to some decimal places, but not enough. On the 9th decimal place the f_aq comes off of a whole number value and causes the calculation to fail. Looks like the workaround is necessary. Thanks!