LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to use the for loop to check each value in the array?

Hi. 


So something that suspose to be pretty simple, is not taking a bit more time. Therefore I am reaching out to the community. 

 

1) I have an 2D string array, that looks like this: 

ChristianLiinHansen_0-1637850156153.png


2) I need to check all values (i.e. in this case only 4 times) that the value stated out from "% as Butane" is not equal or above 1.8. I.e. the little program should do the following: 

a) Get the string array, i.e. ["1.2", "1.3", "1.9", "1.8"] and check if just one of them are equal or above 1.8 in decimal format, some LED on the front HMI should light up. 

3) I made it like this, but is there a better way?

ChristianLiinHansen_1-1637850450576.png

 

0 Kudos
Message 1 of 5
(1,887 Views)

This is basically correct. Almost every code can be improved, though. For example, the following code will do the same without a for loop and for an arbitrary number of peaks.

example.png

Paolo
-------------------
LV 7.1, 2011, 2017, 2019, 2021
0 Kudos
Message 2 of 5
(1,879 Views)

Hi, thanks for your reply. 

I actually have another issue/question. 

If I want to light up an LED, if any of them were true, how can I do that? I was thinking to use the shift register and then do like this... But perhaps I am getting too tired now 😄 

ChristianLiinHansen_1-1637856431797.png

 

 

0 Kudos
Message 3 of 5
(1,869 Views)

Just use the Or Array Elements function in the Boolean palette.

Paolo
-------------------
LV 7.1, 2011, 2017, 2019, 2021
0 Kudos
Message 4 of 5
(1,866 Views)

@ChristianLiinHansen wrote:

Hi, thanks for your reply. 

I actually have another issue/question. 

If I want to light up an LED, if any of them were true, how can I do that? I was thinking to use the shift register and then do like this... But perhaps I am getting too tired now 😄 

ChristianLiinHansen_1-1637856431797.png

 

 


Can you explain what that picture has to do with the question?? This code is significantly worse than your first one. (e.g. x OR FALSE just returns x unchanged, the convoluted use of the shift register just makes you lose the value from the last iteration. Code does not scale well, for example if the array has 1000 elements the next time, you need a much bigger monitor and a few hours of work, etc.)

0 Kudos
Message 5 of 5
(1,859 Views)