LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

a kind of tricy, sort 2D data

I am working on a tricy rearrangement. I have a 2D array for instance;
aaa  vvvv
bbb  fffff
ccc  bbbb
ddd  aaa
eee  bbbb
fff     aaa
 
I want place mouse in a cell, for instance cell (0,0), which is aaa
and then click a switch, it will change 2D array to:
aaa   vvvv
ddd  aaa
fff     aaa
bbb  fffff
ccc  bbbb
eee  bbbb
 
That is to bring all rows, which have content "aaa" in the second column to next to the first row, which the cell (0,0) "aaa" is in.
The should work for any cell in the first column.
Any help, please.
 
0 Kudos
Message 1 of 10
(3,400 Views)
This is not really a sorting problem. Just read the value in the selected column then find all rows that match it in the second column.
 
 
There are a few loose ends in your problem formulation, e.g.:
 
Should the first row always be rearranged to have the selected value on top? If not, where should e.g. the matches be placed if you e.g. click on fff?
0 Kudos
Message 2 of 10
(3,385 Views)
You got what I need. It is not neccessary to place all matched cells on the top, as long as their row are next each other. I said sort, means finally the program should do, all cells in the first column will be compared with the cells in the second column, and rearrange all of cells like the example for the cell (0,0).
0 Kudos
Message 3 of 10
(3,375 Views)
This seemed like an interesting project so I wrote a vi that will do what you are looking for.  Run the vi, click in any array box, and the output will be sorted by rows according to the text in the box that was clicked.  The way it works is that the value of the selected box is used to compare against each row of the array.  If a match is found, that row number is put into a match array.  If no match is found, that row number is put into a non-match array.  After all rows are compared, the output array is built by extracting the match rows and putting them into the output array first, then the non-match rows are added on.  See attached vi.

Message Edited by tbob on 08-29-2005 03:22 PM

- tbob

Inventor of the WORM Global
Message 4 of 10
(3,365 Views)
OK, I made one too. 😉
 
Just double-clicking any row in the table will read its element in the first colum and then ensure that all rows with that element in the second column be adjacent to each other. (Actually, it does not move the first match, but will move subsequent matched right below the previous match). Modify as needed. (LabVIEW 7.1).
0 Kudos
Message 5 of 10
(3,361 Views)

Thanks tbob and altenbach for making efforts.

Tbob's trickysort.vi works exactly like I need. Altenbach's matchfirst.vi seems not work well. Only works by doulb-clicking the second row.

Anyhow, thank you very much. I really learned a lot. Before, I did not try to use this help source so that I sometimes spent days in working on a small program.

 

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


@detech wrote:

Tbob's trickysort.vi works exactly like I need. Altenbach's matchfirst.vi seems not work well. Only works by doulb-clicking the second row.


Please test again. It will work by double-clicking the first row or the second row. However, once they are double-clicked, the second column fully satisfied the requirements and no further changes will be made even if you double-click again. All equal elements are now already next to each other! (Remember you did not specify they should be in a certain location with respect to column 1, just next to each other). For all other rows, there are only 0 or 1 matching elements in columns 2 and no further action is needed and nothing will happen when you double-click.
 
It will be more obvious with much larger input tables. 😉
 
 
0 Kudos
Message 7 of 10
(3,337 Views)

I still can not make it.

lets see:

aaa www

bbb ffff

ccc bbb

ddd aaa

eee bbb

ffff aaa

rrr ccc

ppp ffff

www rrr

shoud be like (please see rows with aaa):

aaa www

ddd aaa

ffff aaa

bbb ffff

ccc bbb

eee bbb

rrr ccc

ppp ffff

www rrr

You program gives:

aaa www

bbb ffff

ccc bbb

ddd aaa

ffff aaa

eee bbb

rrr ccc

ppp ffff

www rrr

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

Ah well, there comes the "modify as needed" into play. It's all about communicating the exact requirements. 😮

In my example, the matching items in column 2 ARE next to each other as per your specification. You did not clearly specify that the originally clicked column must also be next to them ;), but I guess that's what you actually want.

So, what should happen If I click e.g. the last row (different array data)? Should the matching rows be placed above it? Should the clicked row be moved up?

0 Kudos
Message 9 of 10
(3,319 Views)
If clicking the last row, the matching row will be the the row with "www" in the sencond column, which should be next to the last row (may be above it, or the clicked row be moved up).
0 Kudos
Message 10 of 10
(3,308 Views)