07-12-2010 11:48 AM
Hello all-
This may be a dumb question, since I'm still not even entirely clear on what the differences are between matrices and, 2D Arrays in LabView. So far the only distinction I've seemed to find is that some array functions return errors when matrices are input and vice versa.
Anyway, here's my question.
Suppose I have a matrix where the first column represents "Values" that have been measured and the second column represents "Counts". I would like to take an un-ordered matrix (i.e., the value column is not ordered) and get back a matrix that has had its rows re-arranged according to the values in the first column.
For example, if my matrix was:
[5 1;
0 11;
1 5;
3 10]
I would like labview to be able to return:
[0 11;
1 5;
3 10;
5 1]
When I was trying to figure out how to do this (without writing my own sorting routine which, admittedly, would not be too bad, but I'm a lazy programmer ), the only thing I found that came close was the "Sort 1D Array" subVI. However, even if I were to store the values in one array and the counts in another array, all I would be able to do is sort the values array. I would not be able to tell what re-ordering labview performed, which I would need in order to perform the same re-ordering on the counts.
I'm a bit surprised that there isn't a quick, intuitive way to do this (at least that I can find). One feature addition to LabView that could help with this problem would be if the "Sort 1D Array" routine returned a second output -- a vector with the index mapping used -- similar to MATLAB. From the MATLAB help for the "sort" function:
"[Y,I] = SORT(X,DIM,MODE) also returns an index matrix I. If X is a vector, then Y = X(I)."
Of course, there may be a quick workaround for this that I'm missing...
Solved! Go to Solution.
07-12-2010 11:57 AM
Have a look at this post. I am sure you can modify it for your particular data type. 🙂
(slice out the first colum, create sort key, rebuilt 2D array according to key)
07-12-2010 01:21 PM
Thanks! That's a very nice, quick solution. I'm still a bit surprised by how few useful functions are supplied by LabView for dealing with multi-dimensional arrays and matrices (perhaps I'm a bit spoilt by MATLAB).
Still, this is a nice work-around for the time being!
07-12-2010 02:00 PM
If you read the post I quoted, it also points to an openG version. No programming needed. 🙂