08-27-2010 08:27 AM
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).
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.
08-27-2010 09:33 AM - edited 08-27-2010 09:37 AM
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 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.
08-27-2010 10:12 AM
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.
08-27-2010 10:20 AM
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.
08-27-2010 10:32 AM
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.
08-27-2010 12:05 PM
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.
08-30-2010 07:49 AM
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!
08-30-2010 09:54 AM - edited 08-30-2010 09:57 AM
@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.
(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.
08-30-2010 09:56 AM - edited 08-30-2010 09:57 AM
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.
08-30-2010 10:04 AM - edited 08-30-2010 10:10 AM
Sorry, i might have been misled by Damien's post. It seems you are not searching for an element, but for a matching row.