LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Array of clusters

Solved!
Go to solution

Hello,

 

I am working on a project for school. I have a subVI that produces a 1d array of clusters of 6 elements. In other words, the subVI produces an array of patients with a cluster of (number, age, height, weight, gender). I need to retrieve the height and weight data for each patient and perform the calculation (500*Weight)/H, then sort the patients based on the calculation and put them into specific categories (<x, >y). How do I do that? How do I retrieve only weight and height and perform a calculation for every patient in the original array of clusters?

0 Kudos
Message 1 of 21
(3,216 Views)

Hi taras,

 

I'm going to quote just little bits, so apologies that this won't form very nice sentences...

 

@taras01 wrote:

How do I ... perform a calculation for every patient in the original array of clusters?


For loop with autoindexing input

 


@taras01 wrote:

I need to retrieve the height and weight data for each patient ... How do I retrieve only weight and height


Unbundle by Name on the cluster (inside the For loop)

 


@taras01 wrote:

... sort the patients based on the calculation and put them into specific categories (<x, >y). 


You can probably do this most effectively with something like Threshold 1D Array (where the array is the threshold values), but I find that function to be a bit of a pain to understand - you can alternatively cascade Case Structures or use a series of Conditional Tunnels out of the For loop (that might be useful in any case), but this will be more messy on the block diagram.

 

Good luck!

 


GCentral
0 Kudos
Message 2 of 21
(3,177 Views)

The new Sort 2D Array.vim might help.

 

You won't learn how to DIY though 😉.

0 Kudos
Message 3 of 21
(3,165 Views)

Hi,

 

Sort1DArray can also sort an array of clusters! Sort order is defined by cluster element order - as written in the help...

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 4 of 21
(3,147 Views)

@GerdW wrote:

Sort1DArray can also sort an array of clusters! Sort order is defined by cluster element order - as written in the help...


Up and downs to both...

 

I wouldn't mind another sorting .vim, where you wire an array of clusters, and where you can pick which element(s) to sort on.

0 Kudos
Message 5 of 21
(3,142 Views)

wiebe@CARYA wrote:

@GerdW wrote:

Sort1DArray can also sort an array of clusters! Sort order is defined by cluster element order - as written in the help...


Up and downs to both...

 

I wouldn't mind another sorting .vim, where you wire an array of clusters, and where you can pick which element(s) to sort on.


Is that possible with a VIM?  You might have to venture into XNode territory for that.

"If you weren't supposed to push it, it wouldn't be a button."
0 Kudos
Message 6 of 21
(3,116 Views)

@paul_cardinale wrote:

wiebe@CARYA wrote:

@GerdW wrote:

Sort1DArray can also sort an array of clusters! Sort order is defined by cluster element order - as written in the help...


Up and downs to both...

 

I wouldn't mind another sorting .vim, where you wire an array of clusters, and where you can pick which element(s) to sort on.


Is that possible with a VIM?  You might have to venture into XNode territory for that.


Probably either not efficiently or not cleanly.

 

I think you'd have to use cluster to variant.

 

I don't recall a practical way to get a (dynamically specified) cluster element. That would be great for .vim development. Maybe the change in recent plans will make things like this possible...

 

A lot of growable functions call exported LabVIEW.exe functions. Maybe unbundle uses one too. That would make it possible, but it would be nasty.

0 Kudos
Message 7 of 21
(3,077 Views)

wiebe@CARYA wrote:

@paul_cardinale wrote:

wiebe@CARYA wrote:

@GerdW wrote:

Sort1DArray can also sort an array of clusters! Sort order is defined by cluster element order - as written in the help...


Up and downs to both...

 

I wouldn't mind another sorting .vim, where you wire an array of clusters, and where you can pick which element(s) to sort on.


Is that possible with a VIM?  You might have to venture into XNode territory for that.


Probably either not efficiently or not cleanly.

 

I think you'd have to use cluster to variant.

 

I don't recall a practical way to get a (dynamically specified) cluster element. That would be great for .vim development. Maybe the change in recent plans will make things like this possible...

 

A lot of growable functions call exported LabVIEW.exe functions. Maybe unbundle uses one too. That would make it possible, but it would be nasty.


You can use data type parsing to pick out the dynamically named cluster element, but of course the values come out as variants which aren't sortable.  And even if you could sort on them, how on Earth would you put the array of clusters back together?

"If you weren't supposed to push it, it wouldn't be a button."
0 Kudos
Message 8 of 21
(3,059 Views)

@paul_cardinale wrote:

wiebe@CARYA wrote:

@paul_cardinale wrote:

wiebe@CARYA wrote:

@GerdW wrote:

Sort1DArray can also sort an array of clusters! Sort order is defined by cluster element order - as written in the help...


Up and downs to both...

 

I wouldn't mind another sorting .vim, where you wire an array of clusters, and where you can pick which element(s) to sort on.


Is that possible with a VIM?  You might have to venture into XNode territory for that.


Probably either not efficiently or not cleanly.

 

I think you'd have to use cluster to variant.

 

I don't recall a practical way to get a (dynamically specified) cluster element. That would be great for .vim development. Maybe the change in recent plans will make things like this possible...

 

A lot of growable functions call exported LabVIEW.exe functions. Maybe unbundle uses one too. That would make it possible, but it would be nasty.


You can use data type parsing to pick out the dynamically named cluster element, but of course the values come out as variants which aren't sortable.  And even if you could sort on them, how on Earth would you put the array of clusters back together?


Once you know the order (which is difficult because this can, for now, only be done with variants), the sorting probably isn't that hard. The vim will adapt to the array type, and if you wire an array of clusters, an order array of clusters can come out.

 

If we had a way to unbundle a strong typed element (by index or by name), we'd get a lot more power from our .vims...

 

Sadly, an 'unbundle' export function doesn't exist. The compile can probably deal with this through pointers... Much more efficient, but sadly we can't do that trick. Or can we? Not sure. 

0 Kudos
Message 9 of 21
(3,054 Views)

I got a "Sort 1D Array Of Clusters" sort of working...

 

There are caveats:

1) Getting the number of elements is tricky. To do this efficiently (not with variants), you'll have to make a .vim with cases that unbundle a cluster of each size, unbundling the last element I've now scripted this for clusters up to 200 elements. If you have more elements, you pay the price of using variant magic... But if you have 200 element clusters, you have other problems to worry about. 

 

2) All elements in the cluster are compared. Even if you want to sort on just one element... This is because we can't actually get individual elements (without variant magic). We can use compare elements, and get a cluster of Booleans, and convert it to an array, and get it's element...

 

3) Because we're converting a cluster of Booleans to an array, this will fail if the cluster is nested. Comparing a cluster with a cluster will result in a cluster of Booleans and a cluster of Booleans, and we can't convert that to an array (easily, without variant magic).

 

If I can solve 3, 2 is probably also solved, and vice versa...

 

EDIT: A 'solution' would be to make 200 VIs to compare element 0-199 and call it in a case... I'm still brainstorming about a single VI that either compares or returns a specific element practically (and without variant magic).

0 Kudos
Message 10 of 21
(3,030 Views)