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
(1,576 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 LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 15
(1,556 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.

0 Kudos
Message 3 of 15
(1,518 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

 

0 Kudos
Message 4 of 15
(1,515 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
(1,495 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.)

0 Kudos
Message 6 of 15
(1,493 Views)

Really helped me a lot.Thanks.

0 Kudos
Message 7 of 15
(1,482 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
(1,480 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 LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 9 of 15
(1,478 Views)

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

LV version 2020.

0 Kudos
Message 10 of 15
(1,473 Views)