08-07-2019 11:37 AM
Good Morning
I know my question is weird but I'll try to explain I have a 2D array where I need to delete rows only taking in count one element, and with the rest of the elements get an average and keep this dat6a in the new array.
I attach the snippet of my code and a image eplaining what I trying to do.
Greetings from Mexico
Solved! Go to Solution.
08-07-2019 12:36 PM
All you probably need is a single loop. Do you want to average rows or columns?
(Sorry, posting by phone)
08-07-2019 12:40 PM - edited 08-07-2019 12:56 PM
Since your snippet showed 2017, I've attached a fairly ugly 2017 solution.
If you have access to 2019, you can use a map from double to array of doubles, and massively simplify the code 🙂
Indeed, you can check Christian Altenbach's (poster above) presentation at NI Week for information about Variant Attribute to Map comparisons!
Here's a slightly tidied version (attached as v2) for reading without LabVIEW.
Unfortunately, Varriant Attributes won't add a new attribute if it doesn't exist using the Get/Set In-Place structure, so you need that case structure afterwards.
Using the Map(DBL, DBL[]), you can set the behaviour to "Modify or Add" (or similar phrasing) to avoid the need for the CS.
08-07-2019 12:53 PM
Hi the average will be the columns
08-07-2019 12:58 PM
Muchas Gracias (meaning Thanks in Spanish) cbutcher, I tried the code and it works great!!! Now I'm examinating the block diagram to attach to a bigger code.
08-07-2019 01:02 PM
@jalex0906 wrote:I know my question is weird but I'll try to explain I have a 2D array where I need to delete rows only taking in count one element, and with the rest of the elements get an average and keep this dat6a in the new array.
I attach the snippet of my code and a image eplaining what I trying to do.
OK, whatever you are describing has little to do with the code you are showing (which makes no sense anyway)..
What do you mean by "taking in count one element"? Which element? The first column? User sepcified?
So you want to average all columns that have a "2" as first element? Your example only contains "2s" in the first column. Is this normal or are there also other possibilities?
When attaching a snippet, it helps if the input array contains typical default data. It also helps if the default data is not degenerate. If there can be otehr elements beside "2" in the first column, that should be part of the example data.
08-07-2019 01:13 PM
Here's what I had in mind, but maybe I don't understand your problem correctly. (The FALSE case is just wired across)
08-07-2019 01:32 PM - edited 08-07-2019 01:33 PM
And if you want an average for all unique elements in the first column, here's what you could do. Maybe this can give you some ideas.... (Of course you need to remember that DBL comparisons might be dangerous, depending on where the data comes from)
08-07-2019 02:18 PM
That is great...In my case my data comes out of DAQ Device
08-08-2019 12:44 PM
For comparison, here's how my last code would look like using a map (only LabVIEW 2019+). Much less obscure than the variant attribute method. 😄 Same result. 😉