LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Find newest element in 2D array according time

Solved!
Go to solution

hello,guys

I met one issue that can not get newest value in 2D array and tried to find ways to solve it.

2020/11/25 9:04:49 A
2020/11/25 9:04:49 B
2020/11/25 9:06:49 A
2020/11/25 9:04:49 C
2020/11/25 9:08:49 A
2020/11/26 9:04:49 B
2020/11/26 9:04:49 A
2020/11/27 9:04:49 C
2020/11/27 9:04:49 A

I want to get newest value A,B,C .Can you share your idea?I tried to use OpenG function but failed.

 

 

0 Kudos
Message 1 of 15
(298 Views)

Hi Jonathan,

 

suggestion:

  • convert the first column of the 2D array into an array of timestamps
  • bundle each item of the 2nd column with the corresponding item of the timestamp array into an 1D array of clusters
  • sort this 1D array of clusters: it will get sorted by the cluster element order, which should be [item ABC, timestamp]
  • reverse the 1D array
  • get the first element: it will be the most up-to-date entry for item C
  • now search for item "B": the first search result will be the latest entry
  • now search for item "A": …

See how far you get and attach your VI (not just an image of parts of block diagram)!

Best regards,
GerdW

using LV2011SP1 + LV2017 (+LV2020 sometimes) on Win10+cRIO
0 Kudos
Message 2 of 15
(278 Views)

I assume you want the newest row for each unique item in the second column.

 

If you have a recent LabVIEW version, I would use a MAP.(key: string, Value: timestamp or equivalent)

 

Iterate over the 2D array and add new Map entries with the element from the second column as key and the time as value. Whenever the key already exists, update the value with the larger of the old or new timestamp. At the end, extract all map elements. This makes it most flexible, because you don't even need to know what the possible values of the second column are.


LabVIEW Champion. It all comes together in GCentral GCentral
What does "Engineering Redefined" mean??
0 Kudos
Message 3 of 15
(240 Views)
Solution
Accepted by topic author Jonathan_Rao

@altenbach wrote:

If you have a recent LabVIEW version, I would use a MAP.(key: string, Value: timestamp or equivalent)


Here's how that could look like:

 

(Note, since you seem to prefer pictures over VIs, I only show a code image ;))

 

altenbach_0-1606325196747.png

 


LabVIEW Champion. It all comes together in GCentral GCentral
What does "Engineering Redefined" mean??
0 Kudos
Message 4 of 15
(237 Views)

altenbach,Thanks a mil.

it seems you used LV 2019 for this solution ,my version is LV 2018.

Is In placement element sructure used in the for loop?I never see it.

0 Kudos
Message 5 of 15
(217 Views)

No, the MAP datatype is only available in LabVIEW 2019 and newer. (You could do something similar with variant attributes, but that'll be more convoluted.)


LabVIEW Champion. It all comes together in GCentral GCentral
What does "Engineering Redefined" mean??
0 Kudos
Message 6 of 15
(215 Views)

Really helped me a lot.Thanks.

0 Kudos
Message 7 of 15
(204 Views)

I tried but it seems not I want.You can check the answer in this topic.It works.

Thanks.

0 Kudos
Message 8 of 15
(202 Views)

Hi Jonathan,

 


@Jonathan_Rao wrote:

I tried but it seems not I want.You can check the answer in this topic.It works.


So "it works" but "it seems not want you want"?

Maybe it's time you attach your current implementation (aka your VI)!?

Best regards,
GerdW

using LV2011SP1 + LV2017 (+LV2020 sometimes) on Win10+cRIO
0 Kudos
Message 9 of 15
(200 Views)

Hi,I attached VI here .Willing to get your proposal.

LV version 2020.

0 Kudos
Message 10 of 15
(195 Views)