LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Sort data with display each move

Solved!
Go to solution

Hy, 

I need a VI witch sort data with 2 aray .

2 array.JPG

 

In this image i have first aray and after sort, first column is position of cd in rack and second column is number of cd.

For sort i use position 6 in rack, this position is free.

For this situation array such as :

1 --- 6

3 --- 1

5 --- 3

4 --- 5

2 --- 4

6 --- 1

 

These are the moves you made ... i need a VI which makes it.

 

EX: 

exemple.JPG

 

Have a nice day .

 

0 Kudos
Message 1 of 15
(3,416 Views)

I need a VI witch sort data with 2 aray

 

...so, write one!

 

This is obviously homework (you don't really need a computer program to tell you how to sort your CD rack, do you?). Which means you are trying to learn programming. Which means you should try and learn programming.

 

When you have a specific question about LabVIEW, post your code and describe what trouble you are having and someone will probably try to help. But no one is going to hand your homework assignment to you on a plate. Man up and get to work.

0 Kudos
Message 2 of 15
(3,386 Views)

bledyuc wrote:

I need a VI witch sort data with 2 aray .

 

(Picture of two 2D arrays with two columns and five rows)

 

In this image i have first aray and after sort, first column is position of cd in rack and second column is number of cd.

For sort i use position 6 in rack, this position is free.

For this situation array such as :

1 --- 6

3 --- 1

5 --- 3

4 --- 5

2 --- 4

6 --- 1

 

These are the moves you made ... i need a VI which makes it.

 

EX: 

(picture of a 2D array with four elements)


OK, so are you just looking to implement sorting a 2D array by a certain column or are you trying to implement a specific (seemingly quite inefficient) sorting algorithm.

 

In any case, your question needs to be much clearer!

 

In the first picture you show two different 2D arrays. What's the significance of the first column? What is the sigificance of the right and left array? Is the left array a typical input and the right array a corresponding result? The data in the first column seems redundant. All you need is the second column as a 1D array where the value of the original first colum corresponds to the array index+1. Right?

 

It seems all you do is sort the second column, leaving the first column untouched. A typical and efficient sort algorithm operates in place, so why would you want to use an extra row for temporary storage?

 

At the end, you show a picture of a 2x2 2D array with four elements. Does it have anything to do with the question or answer? Please explain.

 

In any case, try to solve it as much as possible and if you get stuck, attach yor VI attempt. Make sure the controls contain typical inputs. 

0 Kudos
Message 3 of 15
(3,365 Views)

Ok, i try to be more explicit . 

I have robot controlled through a serial port, i make a VI that we control. First part of aplication, my robot takes CD ( have a code QR with a number ) a rack a move then to a camera, that reads the code and after that robot put the CD in rack in same position. After read all cd i have this array : 

position with read.JPG

 

I need to know which are movements that have to make the robot for sort all cd depending on numeber of QR code. 

Ex: Move cd13 on position 1 to position 6 ( use a other position for sorting ) ( position 1 is free )

Move cd12 on position 3 to position 1 ( after that CD12 is in corect positon ) ( position 3 is free )

Move cd 15 on positon 5 to position 3 ( after that CD15 is in corect positon ) ( position 5 is free ) 

Move cd 32 on positon 4 to position 5 ( after that CD32 is in corect positon ) ( position 4 is free ) 

Move cd 23 on positon 2 to position 4 ( after that CD23 is in corect positon ) ( position 2 is free ) 

Move cd 13 on positon 6 to position 2 ( after that CD13 is in corect positon ) 

 

After that my array is 

ddd.JPG

 

 

i try then : 

 

exem.JPG

 

0 Kudos
Message 4 of 15
(3,350 Views)

So, how should the desired output look like?

 

(sorry, your code image is too scrambled and truncated to provide any useful information. Why don't you attach the actual VI instead?)

0 Kudos
Message 5 of 15
(3,329 Views)

EXemple of output:

exemple.JPG

 

First line : Move CD on position 3 to 6 

Second line : Move CD on position 5 to 3 

 

 

 

0 Kudos
Message 6 of 15
(3,321 Views)

So have you worked out the algorithm you need?

 

1. You need to get your desired order (by sorting your initial order) so you know what needs moving.

2. Find the first cd that is out of place and move it to the empty slot.

3. Determine which cd belongs in the slot just vacated by looking it up in your desired array.

4. Find that cd in your actual array (search for it)

5. Move the cd into the vacant slot where it belongs.

6. Repeat from 3 until the actual matches the desired.

 

Here is a very quick knock up of that. Note I have used a simple max value to represent the empty slot, and this is certainly not the most efficient sort algorithm anyone has ever come up with, but for a few cds it will probably do. The output array lists which cd to move from slot to slot. Slot indexes are zero based.

 

Can you adapt this to your application? (I gave up trying to understand your code.)

 

CD Sort.png

Message 7 of 15
(3,306 Views)

I don't undestand the output .. and number 65535 ( i know is maxim in this format of number )  ... i don' t adapt then ... i don't know how ?

0 Kudos
Message 8 of 15
(3,283 Views)

CD Sort fp.png

 

Start Order are the CD numbers in their original order. It is only a 1D array because there was no point (for me) including another column with the index. We already know the index!

 

Desired Order is where each cd should end up.

 

The 'moves' array lists which cd to move from which slot to which slot - in this case:

move cd 13 from slot 0 to slot 5,

then move cd 12 from slot 2 to slot 0,

then move cd 14 from slot 4 to slot 2, ... etc.

 

Finished Order is a check on where everything ended up.

 

Because in LabVIEW you can't have an empty array element, I needed a way to represent the empty slot. I used 65535 simply on the assumption that there would be no cd with that number. I could have used 0 or -1 (which would have been cleaner) but then it would have sorted to the beginning of the list which I did not want and couldn't be bothered coding for that special case. 65535 was convenient.

 

The output format ('moves' array) is a bit different to your original specification, but its really just a case of which figures you take out of the loop and add to the array. I did it like this because it made more sense to me and seemed more intuitive. You can take the figures and format the output however you like.

 

0 Kudos
Message 9 of 15
(3,270 Views)

notwork.JPG

 

why don't work ?

 

0 Kudos
Message 10 of 15
(3,260 Views)