10-17-2021 07:58 AM
I'm a kind of new in using LABVIEW. I need to build a code that makes the average of a group of data(two columns), in a determinated range of numbers. For example: I need to catch all the numbers beetween 2 and 2.5, in the first column, and makes an average of the values in the second column.
So in order to do that, I build two for loops: One indexed by the array with the values that I need for the intervals and other indexed by data values. The problem is: I want that my loop continues while the value of the first column be beetween the values that we have determined before, so I use an "and " operator, but it appears it did not workout.
PS: if anyone has another idea of how I can make this algorithm, changing the code, I really appreciate it.
10-17-2021 10:51 AM
There are many ways to solve this problem. You are starting off well by generating a (small) 2D array with random numbers (between what and what? -- as you've coded it, how many out of the 10 sets of two that you generate will have a number between 2 and 2.5 in the first column, as your question outlines?) as a Test Array.
So what do you want to do? You want to take this Array and do two things, sequentially, to it.
First, "catch all the numbers between Bottom and Top" (I made up variable names, where you can enter 2 and 2.5, if you want).
So you take your 2D Array and pass it into a For Loop (because you've learned that Arrays and For Loops "naturally" go together).
Have you learned about Indexing versus Non-Indexing Tunnels? Non-Indexing Tunnels consist of a filled-in Square showing the color appropriate to the type of variable, Orange in the case of a Float (like a Dbl), while Indexing look like a Square with a tiny pair of colored Array Brackets, [], inside them, indicating they are meant to pass in one Array Element at a time. So what kind of Tunnel do you want for your "Catch numbers between Top and Bottom". Indexing or Non-Indexing?
Assume that inside the For Loop, you have a single Row element of your initial 2D Array. You want to examine the first Element. Do you know the Array Function that lets you "choose" an Array Element to examine? If not, right-click on the Desktop to bring up the Programming Palette, choose Array, choose a Function that you think might be correct, put it on your Block Diagram, right-click it, and choose "Help" to get LabVIEW to tell you what it does and how to use it.
Now you have the first Element. Do you know how to tell if it is between Bottom and Top? There is a single function on the Comparison Palette that might do it for you -- you might not have encountered it yet, but using the steps in the previous paragraph, you can probably "figure it out".
Now you know if this Row has the second Element between Bottom and Top. Now you need to decide if you want to "export" this entire row, or only the number in the second Column (your description of the Problem didn't seem to specify this) -- at some point, anyway, you'll need to isolate the number in the second column using a technique similar to how you isolated the first element two paragraphs back.
So now you need to get selected Array elements out of the For Loop and into another Array. When you learned about Tunnels, including Indexing and Non-Indexing, did you also learn about "Conditional" Tunnels? [That's all the Hint I'm going to give, except to reread this note if necessary.
Bob Schor
10-17-2021 11:44 AM
All you probably need is one single loop. You also need to define terms such as "catch". Most of your code makes no sense at all. (There is also "Ramp pattern" to do some of the lifting. 😄 )
You have a 1D array of a ramp (48 elements) and I assume you want to do the ranging there, meaning the matching values are adjacent. Then you have a 2D array with 10 rows and 2 columns, i.e. a size that is independent of the ramp size. How are things supposed to relate to each other? (thinking round hole, square peg 😮 )
10-18-2021 07:45 AM
It's not clear to me exactly what you are trying to accomplish. Is this it?
10-18-2021 08:07 AM
Thanks for the answers! I'm sorry for the bad explanation of the problem.
From a ramp pattern array, I need to make the average of a second column of my data, as long as each of the values in the first column are within adjacent ranges of this ramp pattern array. For example: I define an interval going from 2 to 10, with an interval between two adjacent samples of 0.5. The first intervall I would be searching for would be: [2, 2.5]. Then I search for all first column values of my data that are inside in these ranges and I make the average of second column values. After that my next intervalls would be [2.5, 3], and I would repeat the process until I get to 10.
10-18-2021 10:31 AM
So if I understand this right, you want a weighted histogram?
First column: Value, second column: Weight? For each bin, take the sum of weights and divide by the count to get the average.
10-18-2021 11:37 AM
In another words, yes. Does labview has any function that build that? If you could give me any idea of how could i compute the standard deviation in each "bin" it would be nice too. The thing is: In order to compute these two things, I was trying to create an array of arrays, but it seems that labview does not support it. I have a problem in an equipment that takes too much time for make the measures, then i have a large file that acumules measures errors because of its slow measure process.
10-18-2021 12:19 PM
Hi giovas,
@giovas_ wrote:
I was trying to create an array of arrays, but it seems that labview does not support it.
Infact LabVIEW does not support an array of arrays - but it supports an array of cluster of array!
That is the official way to have an array of "subarrays" with varying length/size…
10-18-2021 12:40 PM
The solution depends a little bit on the size of the problem and how much memory thrashing you can afford.
If each bin can accumulate millions of values, Each element of the array should just have a cluster containing [N, Sum(x), Sum(x²)], which is sufficient information to calculate the mean and stddev for each bin. (Have a look here and in the next post for the math)
If the problem is small, each element could just be a cluster containing a 1D array of x values where you keep appending new values using e.g. the IPE structure.
10-18-2021 01:00 PM
@giovas_ wrote:
Thanks for the answers! I'm sorry for the bad explanation of the problem.
From a ramp pattern array, I need to make the average of a second column of my data, as long as each of the values in the first column are within adjacent ranges of this ramp pattern array. For example: I define an interval going from 2 to 10, with an interval between two adjacent samples of 0.5. The first intervall I would be searching for would be: [2, 2.5]. Then I search for all first column values of my data that are inside in these ranges and I make the average of second column values. After that my next intervalls would be [2.5, 3], and I would repeat the process until I get to 10.
See if this works. Will spit out NaN if a 'subarray' has 0 elements.
Instead of worrying about making an array of arrays of different lengths, you can get subarray i and then get the stats of subarray i...
Saying "Thanks that fixed it" or "Thanks that answers my question" and not giving a Kudo or Marked Solution, is like telling your waiter they did a great job and not leaving a tip. Please, tip your waiters.