11-03-2015 07:44 AM
Is it possible to find the max/min value for each row/column of a 2D array without a loop?
Solved! Go to Solution.
11-03-2015 07:56 AM
I recommend using the FOR loop with autoindexing tunnels so that you can do the comparison for each row/column. Your alternative is to use Array Index to get the rows/columns you want and then do the comparison. Not very scalable and way longer to program.
11-03-2015 08:00 AM
The goal is to not use a loop. Is this possible in LabVIEW? For example, in other programming languages, for a 2D array 'A', one could write max(A) and it returns the max of each coumn.
11-03-2015 08:11 AM - edited 11-03-2015 08:12 AM
Hi jmountney,
The goal is to not use a loop.
Is this part of your homework description? That's nonsense…
in other programming languages, for a 2D array 'A', one could write max(A) and it returns the max of each coumn.
When you goal is to find a programming language, that allows the solution without using loops, you should use any of those languages, where "max(A)" not just provides the max value but also the max value of each column. IMHO I find a function "max(array)" misleading when it does not give the max value, but the max value of some arbitrary subarrays…
The LabVIEW solution to find the max of each row/column is to use an autoindexing FOR loop with ArrayMinMax inside…
11-03-2015 08:20 AM
This is not homework. I am trying to find a more efficient way of finding the max of each row in a 2D array other than using a FOR loop. If I use the MATLAB block in LabVIEW, I can write m = max(A, [], 2) to get the max of each row in A. However, the execution time to pass the data back and forth between MATLAB and LabVIEW is too long for my application. Using a FOR loop in LabVIEW is also too time consuming. If I perform the task in the MATLAB environment, the time is only a fraction of the time it takes to execute in LabVIEW. The problem is that I need LabVIEW to do the data acquisition, but the processing time in LabVIEW is excedingly long using indexed arrays in a FOR loop.
11-03-2015 08:37 AM - edited 11-03-2015 08:42 AM
11-03-2015 08:39 AM
@jmountney wrote:
This is not homework. I am trying to find a more efficient way of finding the max of each row in a 2D array other than using a FOR loop. If I use the MATLAB block in LabVIEW, I can write m = max(A, [], 2) to get the max of each row in A. However, the execution time to pass the data back and forth between MATLAB and LabVIEW is too long for my application. Using a FOR loop in LabVIEW is also too time consuming. If I perform the task in the MATLAB environment, the time is only a fraction of the time it takes to execute in LabVIEW. The problem is that I need LabVIEW to do the data acquisition, but the processing time in LabVIEW is excedingly long using indexed arrays in a FOR loop.
I'm very curious what your code looks like then. When done properly, that should take next to no time. Please provide an example.
11-03-2015 09:15 AM
The array size is 50k rows x 100 columns. As an example I have attached a VI that demonstrates what I am attempting to achieve. This process takes a minimum of 35 ms to execute. Equivilantly, in MATLAB, I can write:
A = rand(50e3, 100);
tic
m = max(A,[],2);
1e3*toc
which takes less than 3 ms to execute.
Does LabVIEW automatically take advantage of multicores? Are there ways to make this computation more efficient?
11-03-2015 09:25 AM - edited 11-03-2015 09:27 AM
Hi jmountney,
using parallel execution brings execution time from 27ms to 5ms on my 8-core i7:
Does LabVIEW automatically take advantage of multicores?
General answer: Yes.
More specific answer: it helps to have a basic understanding of what the compiler is doing under the hood…
In your example you have a loop with just one function inside. This will manily run on just one core - unless you tell LabVIEW to use more cores as shown!
11-03-2015 09:36 AM
Thank you.