11-16-2018 08:17 AM
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.
Solved! Go to Solution.
11-16-2018 08:51 AM
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.
11-16-2018 02:43 PM - edited 11-16-2018 02:48 PM
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)
11-16-2018 03:17 PM
@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)
11-18-2018 05:57 AM
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
11-18-2018 01:00 PM
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!
11-18-2018 02:53 PM
@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).
11-19-2018 08:40 AM
Thank you Altenbach,
Exactly what I wanted. Perfect
11-19-2018 02:31 PM - edited 11-19-2018 03:02 PM
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! 😄
11-19-2018 02:58 PM - edited 11-19-2018 03:15 PM
@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).
(Note that this seems similar to your own original solution, just much less convoluted. Maybe you can compare to see where the problem was.;))