LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I change the array to the correct format?

Solved!
Go to solution

I need to change the following array to be sorted in numeric order (right to left and from top to bottom) 

if you can't see the image the array is as follows

 

{[0,1,17,2,3,20,4,5,6,7,8,26,27,14,29,15]

[0,9,0,10,19,0,21,11,12,13,25,0,0,28,0,30]

[0,16,0,18,0,0,33,22,23,24,35,0,0,36,0,37]

[0,31,0,32,0,0,0,34,0,0,0,0,0,0,0,0]}  (sorry for those math people out there for the formatting)...

 

I need the array above to turn out as such

 

{[0,1,0,2,3,0,4,5,6,7,8,0,0,0,0,0]

[0,9,0,10,0,0,0,11,12,13,0,0,0,14,0,15]

[0,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30]

[0,31,0,32,0,0,33,34,0,0,35,0,0,36,0,37]}

 

Does anyone have some idea what I could do in LabVIEW that can sort this out?

Regards,

Mark

 

0 Kudos
Message 1 of 18
(4,035 Views)

Try the attached code. Not sure if this would achieve your goal

.Sort.png

0 Kudos
Message 2 of 18
(4,022 Views)

What are you trying to do?  How does the new array relate to the old one?

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 3 of 18
(4,002 Views)

mark.eckhoff wrote:

 

{[ 0, 1,17, 2, 3,20, 4, 5, 6, 7, 8,26,27,14,29,15]

 [ 0, 9, 0,10,19, 0,21,11,12,13,25, 0, 0,28, 0,30]

 [ 0,16, 0,18, 0, 0,33,22,23,24,35, 0, 0,36, 0,37]

 [ 0,31, 0,32, 0, 0, 0,34, 0, 0, 0, 0, 0, 0, 0, 0]}

 

I need the array above to turn out as such:

 

{[ 0, 1, 0, 2, 3, 0, 4, 5, 6, 7, 8, 0, 0, 0, 0, 0]

 [ 0, 9, 0,10, 0, 0, 0,11,12,13, 0, 0, 0,14, 0,15]

 [ 0,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30]

 [ 0,31, 0,32, 0, 0,33,34, 0, 0,35, 0, 0,36, 0,37]}

 


This result does not look like it is "sorted in numeric order (right to left and from top to bottom)" in any recognizable way. It semes that the zeroes have a special meaning such that some out-of-order elements get replaced by zero and then inserted into the same column, but in a later row. The insert pont seems to be picked such that the row is sorted.

0 Kudos
Message 4 of 18
(3,964 Views)

If you can explain the logic of how this is supposed to work we might be able to help you.

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 5 of 18
(3,942 Views)

Hi Mark,

 

I dont know whether you have tried to solve this or not, but I did some practise on this. Please find the attachment.

I have tested it  with your example only so not sure about its full functionality.

If you have any question just reply me.

 

Kudos are always Welcome..... 🙂

Vinal Gandhi, CLA
0 Kudos
Message 6 of 18
(3,894 Views)

@Vinal_G wrote:

I have tested it  with your example only so not sure about its full functionality.


Please add the quoted sample data to the control, make current values default, save the VI and attach it once more.

0 Kudos
Message 7 of 18
(3,877 Views)

Done.

 

 

Vinal Gandhi, CLA
Message 8 of 18
(3,869 Views)

But what does it do?  It's very convoluted and no comments.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 9 of 18
(3,849 Views)

Sorry Everyone, 

I haven't had any time yet to test the solutions quite yet due to the holiday and I don't have access to my LV project and machine so I won't be able to check back in with you guys until Monday morning.

Regards,

Mark

0 Kudos
Message 10 of 18
(3,822 Views)

I have to check this on my other machine but I think it may work for my use case. Thanks


@Vinal_G wrote:

Done.

 

 


 

0 Kudos
Message 11 of 18
(1,356 Views)

Can you give us a little bit of background information.

 

  • What does the input array represent?
  • Where does it come from?
  • What is the output array used for?

That kind of information would g a long way helping us understand and solve the problem.

At the moment is is just a puzzle to look for pattern where only a single example is available.

There are millions of possible solution that covert your input array to your output array. Most likely only one is correct.

0 Kudos
Message 12 of 18
(1,346 Views)
Solution
Accepted by topic author mark.eckhoff

OK, I thought that Vinal's solution above looked overly complicated. Here's what I came up with instead... (LV 2013)

 

...seems to work just fine. 😄

 

 

Download All
Message 13 of 18
(1,335 Views)

Alright, 

I have some background to this issue to clarify for everyone. 

 

The array that I attached corresponds to a collection of parsed data files. I have been working on a sorting function to export to an Excel Spreadsheet that sorts Flow Rates from different devices into a sorted Row Column Array. The Column of 0's is there to actually work as a null and has no significance whatsoever but to clean up my data (I remove this at a later step). 

I will attach my code too to clarify some more I have another VI previous to the compilation of this one that Parses the data from text files and sorts them into an array as well. 

 

The reason for the sorting process here was to sort the indicies of the sorted arrays to line up in my output array accordingly so they would correspond to the correct sample number if there was a previous sample that did not contain a value under that particular Flow Rate Column. 

 

I hope this works to clarify my particular problem. 

 

Thanks for everyone's help and I hope that what you gave me works - I'll let you know later today.

Regards,

Mark

0 Kudos
Message 14 of 18
(1,251 Views)

My code makes a few assumptions about the data, for example there cannot be any missing integer. e.g. if the dataset does not contain any "5" at all, the code would fail. If there is a possibility of missing values, a few very minor changes would need to be made.

0 Kudos
Message 15 of 18
(1,228 Views)

Your assumptions are correct for my use case. There will always be a numerical progression that doesn't skip integers for this case. Thanks again.


@altenbach wrote:

My code makes a few assumptions about the data, for example there cannot be any missing integer. e.g. if the dataset does not contain any "5" at all, the code would fail. If there is a possibility of missing values, a few very minor changes would need to be made.


 

0 Kudos
Message 16 of 18
(1,225 Views)

altenbach, 

Ran into a problem that I found that I can't understand why it does this in your code.

Here is a screenshot showing the problem. 

 

For some reason it cuts out my last index at the end. Do have an idea what is doing this?

Regards,

Mark

0 Kudos
Message 17 of 18
(1,044 Views)

mark.eckhoff wrote:

For some reason it cuts out my last index at the end. Do have an idea what is doing this?


Your array does not match the required specification for my code to work, because now your output array needs to be larger than the input array. If this is a possibility, you simply need to pad the original array with a sufficient number of rows of zeroes (e.g. using "reshape array") before starting or do some other conditional manipulation.

 

That should be easy to fix. See how far you get.

0 Kudos
Message 18 of 18
(1,005 Views)