LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

nested conditional statements

Hi all,

 

I am a bit of a noob here. I have to learn Labview for a project so I thought the best way would be to rewrite my MATLAB programs in Labview ... oh boy it's prooving quite hard!

 

So here is the problem I have:

 

I am doing a field integral, a slow amplitude calculation for the Maxwell equations to simulate multi mode operation of semiconductor lasers (Attached also if you are interested). The right hand side boils down to a set of integrals that simplify to exact coefficients based on the relationship between field indices (work in progress). So I have a series of IF else IF else IF ... type of conditional structure. Now this is just a few lines in MATLAB! But Labview makes it pretty hard ... and I really don't like the idea of nested conditions and case strucures.

 

I looked a lot on the forum and couldn't really find an elegant solution (maybe I didn't look hard enough!) So here is the hack I came up with ... (See coeff.vi) I incoded my conditional statements into a boolian array, then turned that binary number into a decimal integer and used that to drive a case structure!

 

Let me know if you guys see any detremental problems with this way of doing things. I would Also appreciate your feedback on 1) How I am populating my arrays INSIDE a tripply nested FOR loop without exiting the loop and 2) If there is a more elegant way of RESETing the shift register at the begining of the program.

 

Thanks everyone,

 

Arash

Download All
Message 1 of 5
(2,826 Views)

Your solution for eliminating nested case structures is the recommended method. I would recommend that youinclude a comment in each case for readability. Simply use the text tool and type your comment. I would STRONGLY advise against using stacked sequence structures. They are not a recommended coding technique. Learn how to use dataflow to control program execution. Also, local variables are not recommended. With a shift register on your loop you can avoid the use of the local variables for the array.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 2 of 5
(2,819 Views)

@asadeghi wrote:

Hi all,

 

I am a bit of a noob here

...... 

I looked a lot on the forum and couldn't really find an elegant solution (maybe I didn't look hard enough!) So here is the hack I came up with ... (See coeff.vi) I incoded my conditional statements into a boolian array, then turned that binary number into a decimal integer and used that to drive a case structure!

 

 

Arash


HA new at LabVIEW?!?! It took me a few years to discover this one, and I only discovered it because someone told me!

0 Kudos
Message 3 of 5
(2,816 Views)
Hi Mark, Thanks for the reply. So regarding using shift registers instead of local variables, I see your point in case of a single loop, but in case of my example, where I have to loop through 3 (or more, say n=2^16!) then what is your suggestion? I don't mind if the code is slow, we have supercomputer clusters here to run the code on for days ... But how about the stability? Any comment on how I can reset the shift register (buried inside a few nested FOR loops) automatically every time the program runs? Also, how would I go about keeping track of the global index in a series of nested FOR loops. In my example I sort of worked around it by using a timing element (not very elegant) Sorry! Too many questions :) Thanks!
0 Kudos
Message 4 of 5
(2,805 Views)

Generally you want to use wires whenever you can. Local variables are not as efficient and they can easily lead to race conditions in your code. These can be very difficult to debug. If you have very large data sets and don't want to consume lots of memory due to data copies (yes, you can get multiple copies of the data when using wires) then you can use what is known as an action engine. (Search for that here on the forums and you will find lots of posts regarding them.) You may want to consider using more subVIs in your code. Simply wire in your inputs and outputs. This also helps you with dataflow. As for initializing a shift register simply wire your initial value to it on the out side of the loop. If you leave it unwired the register will remember the value between calls to that VI. This is crucial for actine engines. If you wire a value to the shift register that will be the value it starts with when you reach that code.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 5 of 5
(2,794 Views)