cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - You can subscribe to a forum, label or individual post and receive email notifications when someone posts a new topic or reply. Learn more! X

Array Issues Breaking For Loop

Theo_Gagner
10-Marble

Array Issues Breaking For Loop

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.

 

For Loop.png

ACCEPTED SOLUTION

Accepted Solutions
Werner_E
25-Diamond I
(To:Theo_Gagner)

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

 

View solution in original post

4 REPLIES 4
-MFra-
21-Topaz II
(To:Theo_Gagner)

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.

Werner_E
25-Diamond I
(To:Theo_Gagner)

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!

Announcements

Top Tags