06-28-2012 10:17 PM
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
06-28-2012 10:58 PM
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.
06-28-2012 11:04 PM - edited 06-28-2012 11:04 PM
@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!
06-28-2012 11:57 PM
06-29-2012 12:46 AM
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.