LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Statistics VI to an Array

Is it possible to take the output of the Statistics VI and create a true array? I've tried numerous configurations but the best I can get is a string of values placed in the just the first element. When the application is stopped, only the last value remains, the array does not increment beyond that.
0 Kudos
Message 1 of 10
(3,651 Views)
Easiest would be to just autoindex on the output tunnel of the main loop. You'll get one array element for each iteration.
 
There are many other ways to do this. Could you attach a simplified version of your code so we can see exactly how your data is generated??
0 Kudos
Message 2 of 10
(3,641 Views)
Hopefully this will show what I'm talking about. The "Max Array" is the one in question.
0 Kudos
Message 3 of 10
(3,635 Views)
Is this what you need? The loop has to iterate 100 times to build up the array. Then Enable indexing on the tunnel where the signal wire maximum passes out of the loop
~~~~~~~~~~~~~~~~~~~~~~~~~~
"It’s the questions that drive us.”
~~~~~~~~~~~~~~~~~~~~~~~~~~
Message 4 of 10
(3,626 Views)

Do yourself a favor and just use "array min/max" from the array palette. It's not worth dealing with dynamic data types in this simple case.

Now simply accumulate your array max (scalar) into an array via a shift register and a "built array" node (Array indicator will be updated at each iteration)  or use autoindexing (array indicator will be updated once the loop finishes). The attached modified sample (LabVIEW 7.1) shows both methods.

Also, since this is a toplevel while loop, it should propably contain a small wait statement.

Message 5 of 10
(3,622 Views)

Thanks for both examples. I'll spend a lot of time chewing on them today.

I didn't mention that I have 22 years experience programming in various flavors of BASIC and VB through VB6, but this is my first forray into working with instruments. Even though I've completed the LabView Basics 1 & 2 courses, I've had a bit of trouble grasping how loops work in LV compared to VB, but even more so with arrays. Arrays in VB are comparatively simple, so I appreciate the insights you've shared.

I bailed out of LV and built the application in VB6 that needed the general array manipulation I asked about. It took a fraction of the time that I wrestled with this in LV. But I couldn't stand not knowing where I went wrong. I will definitely need a grasp of arrays in the future to use LV. (I could use a couse just in LV arrays beyond those tutorial samples that came with the Pro development suite.)

Again, thanks for helping a newbie get his feet wet.
Smiley Wink
0 Kudos
Message 6 of 10
(3,605 Views)
I actually think arrays are easier in LabVIEW than in VB or other text based languages. Your problem in the example you posted was in not understanding how the Convert From Dynamic Data works. You selected 1D array of scalars as the conversion method. Each time the loop ran, it created a new 1D array with a value in element 0. It did not append a new value to an already existing array. As altenbach showed in his example, the correct way to do it and have the array available inside the loop, is with a shift register that holds the array and a build array that appends a new element with each iteration. If you know the size of the array before the loop runs, you can use an Initialize Array wired to a shift register and then use the Replace Array Element. To just make an array available outside the while loop, the best way is with the autoindexing feature of a while or for loop as altenbach also showed and which you used with the inner while loop in your example.
0 Kudos
Message 7 of 10
(3,597 Views)

"Easier" is a matter of experience and, as you pointed out, understanding. I checked my VB6 code and found it took only 20 lines of code to accomplish what I needed without any consideration to "scalar" data or shift registers. No WHILE loops and one of the For/Next loop starts at 21 and counts to 40 (still don't know how to do that in LV).

I started with a printout of a 1987 Japanese DOS BASIC program written on an ancient NEC PC system; a good 50% percent or more that code has no direct usage in VB6. Within a week I had "translated" the code into a complete VB application.

Two weeks trying to just get the data to do what I needed with LV left me feeling like a complete idiot.

But I realize that it is a lack of experience AND understanding. When I can think as well in LV as VB, perhaps I'll be as productive. Who knows?
Smiley Wink

0 Kudos
Message 8 of 10
(3,580 Views)

Twenty lines of code seem like at lotSmiley Wink. Seriously, many of us started with text based languages and the transition was difficult at the beginning but now, LabVIEW coding seems natural and when I have to do anything in C or C++, I feel burdened down.

By the way, one way to do your for loop in LabVIEW is shown in the attachment.

Message 9 of 10
(3,577 Views)
Dennis, thanks for the example.
 
I was really sold on the LV concept early on, I could see the potential and sold my boss on springing for in-house training and even for the Pro. Developer suite - which combined probably cost more than all the PCs and software I've purchased since coming to work here in 1981. But long term I still think it was a wise investment. I'm just a little antsy to get a completed app and it's frustrating to confess I know less than I thought I did.
 
Coding was fun in the the early days, but as I encountered visual software I've appreciated the time savings. By the time I got into web design about 7 years ago, I didn't have the slightest desire to write any more code than I could get by with and I have relied primarily on WYSIWYG editors except for minor tweaking.
 
Looks like I'm turning this into a chat session. Smiley Surprised Sorry about that, it's just feels good to find some top notch LV veterans to chew the fat with. There's about a dozen of us here who have had training but I'm the only one trying to design complete applications from scratch. The rest just want to know how to tweak completed LV apps provided by the "mother company." (Sort of the difference between an engineer and a mechanic, I suppose.)
Message 10 of 10
(3,567 Views)