LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Search 2D Array

I need to search for a 2D array, and report the row index. I have serached the array and mathematics functions, but none can handle this extrememly simple task, that is easily done in all other software,(MATLAB, VB, Excel etc).

 

 

 

22575i85A1B294C08AE8B6

 

I hope I am wrong, and there is a simple VI to handle this task, because I introduced LabVIEW to my colleagues, and I feel embarrased, when they asked me this question, and I can not find a simple VI, but have to start designing a for or while loop for a simple task.

0 Kudos
Message 1 of 15
(4,959 Views)

The idea of a library of functions is that you have everything available to you which you would need in order to do anything you want (in theory). You have everything you need in order to make a search 2d array function, because a 2d array is really just an array of 1d arrays. I'm not sure what MATLAB is doing in the background, but I have a feeling it is doing exactly what you need to program LabVIEW to do...search the 1D arrays that make up the 2D array. They just chose to release that functionality with the package because MATLAB is entirely based around being able to compute on multidimensional arrays. That is not LabVIEW's primary focus. This is what makes MATLAB the number 1 choice for things like dynamic analysis because rotation matrices and matrix manipulation is very easy to deal with in MATLAB. It's their bread and butter. Excel is a computational package, also. Do you mind telling us why you are demonstrating LabVIEW to your colleagues. There are some cases where it is not the best software for what you want to do Smiley Surprised but when it comes to data aquisition and bus interfacing, I think you would be hard pressed to find a better option. Each language has it's pro's and con's, you just have to decide which language the pro's outweigh the cons for your specific task.

Message 2 of 15
(4,944 Views)

Thanks imstuck.

 

Presently we do a lot of data acquisition here, and before I came , they use 3rd party software, and MATLAB for the computational analysis. but I have  convinced them to use LabVIEW for the data acquisition, so we bought LabVIEW, and started using it.

 

However, because of license issue, there are limited number of LabVIEW and MATLAB. So when I do some data acquisition, I will prefer to just finish the analysis with LabVIEW, so long as the computational complexity is not much. Of course I will normally use MATLAB for complex computations.

 

But common.... search for 2D to return the row index should have been included in labVIEW previous version, especially since LabVIEW is getting very popular.

 

In any case, I will strongly advise LabVIEW management to include such trival functions like that in their next version.

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

Try the OpenG array palette. I'm not 100% sure but I'm guessing they have a function for this. Just google OpenG or VI package manager to see how to download these. Also, what version of LabVIEW do you have? Do you have the mathscript/matlab script nodes? You can use these to access many of the same (mathscript) or all the same(matlab script...assuming you have matlab installed on yoru machine) functions within LabVIEW.

Message 4 of 15
(4,925 Views)

imstuck,

 

I will just use a loop to do the job, since have to create executables for most of the things I do.

 

since using MATLAB will create problems(I have to deal with DLL), and mathscript(does not come with the developer suite), OpenG(3rd party might create problems during executable)

 

Thank you and I appreciate your time.

0 Kudos
Message 5 of 15
(4,915 Views)

You are right this is an simple task and probably why is is not a native vi (the palette is large enough), just pass the array in a loop, do a 1-d search and make the loop conditional to stop on a found search (index >= 0), make this a subvi and you will never have to rewrite it again.

Paul Falkenstein
Coleman Technologies Inc.
CLA, CPI, AIA-Vision
Labview 4.0- 2013, RT, Vision, FPGA
Message 6 of 15
(4,892 Views)

It may be faster to reshape the array to a 1D array, do the search (once), then reshape back to 2D (presuming you are using again.  You will need to convert from position in the 1D array to position in the 2D array, but that is a simple operation.

 

Please add this functionality as a suggestion in the LabVIEW Idea Exchange.  I will vote for it!

Message 7 of 15
(4,844 Views)

 


@DFGray wrote:

It may be faster to reshape the array to a 1D array, do the search (once), then reshape back to 2D (presuming you are using again.  You will need to convert from position in the 1D array to position in the 2D array, but that is a simple operation.


 

Here's an old example.

 

 

(To find only the first match, delete the two loop structures. ;))

 

(If there is only one match, you could do a comparison between the array (of any dimension!) and the element to be found, followed by "boolean to 0,1), followed by "array min/max". The index output of the array max is the desired value. :D)

 


@DFGray wrote:

Please add this functionality as a suggestion in the LabVIEW Idea Exchange.  I will vote for it!


 

The functionality we need is is a simple polymorphic VI ("Search array" would replace the current "search 1D array") that accepts arrays of any dimensionality and returns the index as an array, one element for each dimension. The start index would accept such an array too. (There might be some problems incrementing to the next element when searching for multiple occurrences, so we might need some helper tools).

 

The function would search the elements in the order of the flattened array.

 

 

Message 8 of 15
(4,821 Views)

Not scalable if you want to match only part of a row, but assuming you want to match the whole thing, here is a fairly concise way.

 

 

 

 

 

Message 9 of 15
(4,817 Views)

Sorry, i might have been misled by Damien's post. It seems you are not searching for an element, but for a matching row.

 

0 Kudos
Message 10 of 15
(4,803 Views)