04-02-2024 04:57 PM - edited 04-02-2024 05:13 PM
Hi guys. I'm having some trouble displaying multiple readings within a while loop. As you can see from my VI, I have to get an average of the past 10 temp readings which i have achieved. I have to also display those 10 readings. I am trying to display these readings through an array that is set to indicator, but it is showing a broken wire. I may be wrong to be trying this array but I'm not 100%. If anyone has a suggestion on how to display through the array or if anyone has a different suggestion on how to achieve these readings being displayed, ideas are welcome.
04-02-2024 05:08 PM - edited 04-02-2024 05:20 PM
You have 10 scalars, so you could built them into an array for display. Your algorithm is however not scalable. What if you wan to average the last 1000 readings?
Much better would be to rearchitect your code by keeping a 1D array of 10 elements in a single shift register and replace the oldest with each iteration.
Follow the link in my post here.
04-02-2024 05:14 PM
Thank you. I will try that. 🙂
04-02-2024 05:30 PM - edited 04-02-2024 05:31 PM
(You should not mark your post as solution unless it actually is the solution.)
See if this can give you some ideas....
04-02-2024 11:48 PM - edited 04-02-2024 11:50 PM
@EDiddle wrote:
Hi guys. I'm having some trouble displaying multiple readings within a while loop. As you can see from my VI, I have to get an average of the past 10 temp readings which i have achieved. I have to also display those 10 readings. ...
An easiest way (probably) is to use the MeanPtByPt (point by point) function, something like that:
04-03-2024 10:04 AM
@Andrey_Dmitriev wrote:
An easiest way (probably) is to use the MeanPtByPt (point by point) function, something like that:
Yes, my linked presentation (part II) mentions and compares several possibilities.
(look for slide # 12 ... 14 and code \TS9524_NIWEEK_2016_PartII\02-TS9524BenchmarkArrays\RunningAveragesTester.vi)
I thought his discussion is was more about learning LabVIEW basics and how to display the entire data history. You cannot display an array of history values using "mean prbypt", but that was probably the gist of the question here. 😄
If the array should be sorted by age, a rotate&replace would be easy to implement.
04-03-2024 11:49 AM
Something like this?
04-03-2024 12:20 PM
@RTSLVU wrote:
Something like this?
Yes, that's what I meant earlier
@altenbach wrote:
If the array should be sorted by age, a rotate&replace would be easy to implement.
We have to be careful not to move all elements in memory all the time, but I think the compiler will optimize it by just marking the rotation index if everything is wired correctly. (I don't see it as "subarray" in the context help, so I am not sure.) Alternatively we could just replace the oldest element and rotate for display.
I also think it is better to give an average of the partially filled array (as in my code) instead of outputting NaN for the first 9 iterations, but that depends on the problem.
04-03-2024 01:42 PM
A lossy queue works well for this.
04-03-2024 02:45 PM
@altenbach wrote:
@Andrey_Dmitriev wrote:
An easiest way (probably) is to use the MeanPtByPt (point by point) function, something like that:Yes, my linked presentation (part II) mentions and compares several possibilities.
(look for slide # 12 ... 14 and code \TS9524_NIWEEK_2016_PartII\02-TS9524BenchmarkArrays\RunningAveragesTester.vi)
I thought his discussion is was more about learning LabVIEW basics and how to display the entire data history. You cannot display an array of history values using "mean prbypt",
You're right, Christian, I've read this question very quickly and was under assumption that the trouble with averaged array's visualization, otherwise we need buffer, of course.
Thank you for the presentation, very nice. The only small point is — you stated that "all code variations are tested to give identical results". The results are almost identical, but not exactly identical, because floating-point additions are not associative, threfore the averages will be slightly different (and in two ways proposed above as well), usually not critical for most applications.