LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Re: Arrays

Solved!
Go to solution

Hi, I am new in this forum so my apologies if I am not posting this question in the proper place.

 

I need to read an array inside a for loop and display the values outside this loop. The .png attached is a simplification of my problem -the code is just a bit more complex... at least for me

 

Why does it work fine with Meter 1 inside the for loop but Meter 2 outside just reads the last values? I checked the tunnel modes. In every other mode I get a broken wire.

 

Sorry for the simplicity of my problem; I know my level is quite low but help is appreciated.

 

Regards

0 Kudos
Message 1 of 5
(2,420 Views)

juanmg85 wrote:

I need to read an array inside a for loop and display the values outside this loop.


Sounds to me like you need an array indicator.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 2 of 5
(2,407 Views)

Turn on the "light bulb" and watch your code run in slow motion and ask yourself when does what data move from where to where?

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 3 of 5
(2,404 Views)
Solution
Accepted by topic author juanmg85

Dataflow dictates that an output of a function or structure (e.g. the loop here) is only available after the structure has completed. This is one of the core ideas of dataflow and I would strongly recommend you to do a few more tutorials before proceeding.

 

There are quite a few other things wrong with your code, for example:

  • Why do you have a 2D array if you only operate on one row?
  • Why is the array control inside the loop? If it does not change for the duration of the loop, it belongs before the loop and if you only operate on the first column anyway, you can index that out before the loop too. (if the array is allowed to change during the execution of the loop, the outcome seems unpredictable).
  • If you do the above suggestion, you can autoindex on the array and no longer need to wire N of the loop. This also eliminates the "index array" function and you don't need to wire from [i]. If you do that, the loop will automatically run until the array runs out of elements.
  • ...

(Next time, please attach the VI instead of a picture).

 

Here are two code that do bascally the same thing simpler. You only need to wire N in the rare cases where the array is larger, but you only want to operate on the first N points.

 

SlowlyDisplayElements.png

Message 4 of 5
(2,388 Views)

Thanks for your solution and all your tips, altenbach. I understood a few ideas I didn't know before.

The 2D array is 2D in the original code but yeah, in this simplification it wouldn't make sense.

Finally, I've done Core 1 and 2 courses at NI but since I do not work as a developer (but I need to use LabVIEW every now and then) I often lack of practice. Do you know if there is something like a exercises guide with solutions to practice specific topics?

Thanks again 

0 Kudos
Message 5 of 5
(2,312 Views)