LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

3D tables Data Sorting

Solved!
Go to solution

Hi all

 

I have 3D table, I need to convert it to 2D to make some data sorting and then convert it back to 3D table. I created a code that works if I deal with each page of the 3d table alone.

I then added this part of code inside a loop to be able to deals with all pages of the 3d table at once. but I does not work although it is the same code.

 

Please see the attached VI and help me with this problem.

0 Kudos
Message 1 of 10
(3,480 Views)

Why are you using the First Call function inside the loop?  The First Call function only returns true once after clicking the run button.  During any additional iterations of the for loop, it will always return false. 

 

I'm not sure what your sorting algorithm is doing and I don't have the time to try to figure it out but OpenG toolkit has a sorting VI for a 2D array.  It could simplify your code greatly and may be worth checking out.  It may give you some ideas if your own sorting algorithm is necessary.

2018-11-16_8-49-40.png

aputman
------------------
Heads up! NI has moved LabVIEW to a mandatory SaaS subscription policy, along with a big price increase. Make your voice heard.
0 Kudos
Message 2 of 10
(3,467 Views)

What you are doing is not really "sorting" in the classic sense. It seems you are picking all unique elements from the third column, then for each, listing the values of the fourth column in the order they appear.

 

This seems like a perfect scenario for a variant based solution. try it! (For some ideas, you might be able to modify my old code here)

 

(Note that the default values if the "input" array seems incorrect compared to "2D table". It might help fixing that for easier testing)

0 Kudos
Message 3 of 10
(3,438 Views)

@altenbach wrote:

 

This seems like a perfect scenario for a variant based solution. try it! (For some ideas, you might be able to modify my old code here)

 


See if this works for you (LV 2013)... (The error wires prevent error popups in case a key is an empty string)

 

Process3D.png

 

0 Kudos
Message 4 of 10
(3,433 Views)

Hello Altenbach,

 

Thank you for your response. Your code does what I look for, except for that it sorts the rows of he output table according to the WRE Names (2nd coloumn of the input table). I need it to keep the order in the output as it is in the input.

Besides, I really wanted to know what is the error i made in my VI in order to learn from my own mistakes. I could not get why would'nt a running subVI work as expected if enterd in in a loop

 

Thank you again

 

0 Kudos
Message 5 of 10
(3,408 Views)

Your code is too convoluted to really troubleshoot. I won't sit here for an hour to sift through it if a much simpler solution already exists. 😄

 

Yes, my code returns the entries sorted by the key automatically (which seems like a good thing), but it would be trivial to restore the original order at the end with a tiny little bit more code. Try it!

0 Kudos
Message 6 of 10
(3,400 Views)
Solution
Accepted by topic author AboHareth

@altenbach wrote:

 

Yes, my code returns the entries sorted by the key automatically (which seems like a good thing), but it would be trivial to restore the original order at the end with a tiny little bit more code. Try it!


Here's one simple possibility to do that. (There are of course many different ways, so this is just one).

 

MaintainOrder.png

0 Kudos
Message 7 of 10
(3,394 Views)

Thank you Altenbach,

 

Exactly what I wanted. Perfect 

0 Kudos
Message 8 of 10
(3,362 Views)

Note that my solution is general does not assume that the equal items in the third (key!) column are adjacent. If they are guaranteed to be adjacent, an even much simpler solution is possible. Try it. 😄

 

Your problem description does not specify this requirement, but your sample data does. It is not clear if this is just by accident. 😉

It is important to specify the problem exactly! 😄

0 Kudos
Message 9 of 10
(3,354 Views)

@altenbach wrote:

Note that my solution is general does not assume that the equal items in the third (key!) column are adjacent. If they are guaranteed to be adjacent, an even much simpler solution is possible. Try it. 😄 


Here's a simpler solution if we can guarantee that equal elements of the third column are adjacent. (Please verify correct operation. For the test data, it gives the correct output).

 

Process3Dsimpler.png

 

(Note that this seems similar to your own original solution, just much less convoluted. Maybe you can compare to see where the problem was.;))

0 Kudos
Message 10 of 10
(3,349 Views)