10-14-2016 05:58 PM
Hi all,
I am trying to "translate" a very complicated MATLAB code into LabVIEW. Here is the first problem :
Does LabVIEW have any equivalent function as "any" in MATLAB? Below is the definition of the function any in MATLAB.
####
any:
True if any element of a vector is a nonzero number or is
logical 1 (TRUE). any ignores entries that are NaN (Not a Number).
For vectors, any(V) returns logical 1 (TRUE) if any of the
elements of the vector is a nonzero number or is logical 1 (TRUE).
Otherwise it returns logical 0 (FALSE). For matrices, any(X)
operates on the columns of X, returning a row vector of logical 1's
and 0's. For multi-dimensional arrays, any(X) operates on the
first non-singleton dimension.
###
And the specific script that I am trying to implement is: coeff_error=any(abs(coeff-Lim_mean1)>Lim_diff1+1e-3)
Question #2
In the original MATLAB code, I was post-processing a file, which was recorded continuously for 10 mins (with 50fps speed). So I knew how long the recording is: roughly 30,000 frames. So I was able to initialize a matrix in MATLAB to a set size:
coeff_all=zeros(length(coeff),T)
Here, T is roughly 30,000
Now, I am trying to implement this line in LabVIEW, which is running and processing the system in real time, meaning that I won't know (at the time of recording) how big the T is. So, should I skip this step? or is there a way of doing it in real time?
Thanks!
10-14-2016 08:19 PM
@bazingagirlsun wrote:True if any element of a vector is a nonzero number or is
logical 1 (TRUE). any ignores entries that are NaN (Not a Number).
In LabVIEW, an Array has to have elements that are all the same type. So you don't have to worry about mixing "non-zero number" with "logical 1 (TRUE)". So let "Array" be a 1D array of numbers. Pass it through "not equal to zero", then pass the resulting Boolean Array through the "Existential" Boolean operator (the one that looks like a backward "E"), which is True if any element is true. Presto, "Any".
Bob Schor
10-15-2016 11:44 AM
@bazingagirlsun wrote:In the original MATLAB code, I was post-processing a file, which was recorded continuously for 10 mins (with 50fps speed). So I knew how long the recording is: roughly 30,000 frames. So I was able to initialize a matrix in MATLAB to a set size:
coeff_all=zeros(length(coeff),T)
Here, T is roughly 30,000
Now, I am trying to implement this line in LabVIEW, which is running and processing the system in real time, meaning that I won't know (at the time of recording) how big the T is. So, should I skip this step? or is there a way of doing it in real time?
Sorry, I didn't pay attention to the second question.
What is it you are trying to do? What do the data look like? When you "process it in real time", do you need to have "all of the data so far" to process the current piece of data, or are you able to work with, say, the last 100 points? [Answering the first two questions will probably provide the answer to the third ...].
Something you should definitely consider, particularly if you are needing to do simultaneous data acquisition and processing, is to do these two operations "in parallel", at the same time in independent loops. This is often called a Producer/Consumer Design Pattern, as the Data Acquisition "produces" data and the Data Processing (loop) "consumes" it. One way to see this in action is to open LabVIEW, go to File, New ... (the dots are important!), look under VI, From Template, and find Producer/Consumer Design Pattern (Data). Create a VI from this Template and study it.
One virtue to knowing how big your data will be, as you've noted, is you can pre-allocate storage (such as an Array of the right size) for it. Trying to "grow" the array as you go can be fraught with problems, both in terms of CPU time and memory resources. An alternative storage scheme that almost surely will allow all of the data to be stored is to write it to a file as it is generated (you almost surely have more disk space than memory) -- when you finish generating the data and close the file, you can simply re-open it, allocate a memory array to hold everything (because you know the file's size), and read it in all at once (this will be especially rapid if you read/write a binary file, not a bad file format for a temporary intermediate-storage file).
Bob Schor