If/else statement in the MathScript node

I want to write if/else statement in MathScript node.

If (Yes is Yes)

{

a = 0;

}

other (no = no)

{

b = 1;

}

'Yes' and 'No'--> of Type String

'a' and 'b'--> Type Double

Hi johndoe.

Thank you for contacting National instruments.

I would like to highlight a number of items which you may find useful for the implementation of an if-else statement in a MathScript node.  The first is a book white tutorial, which the second part explains how to use LabVIEW MathScript node. The second is an article describing the required syntax to write functions and scripts in the MathScript node, including instructions for the use of the If-Else statements.

I hope that these help. Please let me know if you need additional assistance.

Kind regards

James

Tags: NI Products

Similar Questions

  • '' If '' dosnt works at the mathscript node

    Hello

    I have a strange problem in mathscript node, can u help me?

    I just wrote a simple conditional style in the mathscript node, but it dosent work and have attached the error! my software has problem?

    Best Regarsd

    Behzad

    The problem is that your "out" is not defined, as executed in your script. Maybe it's what you want instead

    out = - 1; % define value as default for the

    If in == 7

    out = 6;

    end

    Kevin C.

  • Need help on how to create the transformation of the Park by using the MathScript node?

    Hello

    I want to generate a transformation of the Park by using the MathScript node. But there is an error message which confused me. Please can someone help me to have a look of my program? Thank you!

    The error message is "error-90011 occurred in error in the function mail to line 1.  The sizes of the input matrices are incompatible.
    Check that the matrices have the same size or one is a scalar.

    Possible reasons:

    LabVIEW: Sizes of the input matrices are incompatible.  Check that the matrices have the same size or that one is a scalar".

    Hello

    The problem is that all of your entries to the MathScript node are vectors.  All entries of the vector to the MathScript node becomes vector lines.  A multiplication of two vectors lines generates a size mismatch error.  If you really want a scalar of this multiplication of output (by calculating the dot product of vectors), then you have to bring your 'a', 'b' and 'c' vectors or your vector of 'x '.  If you want everything just multiply your elementwise vectors and produce an output vector, you must use the elementwise multiplication operator '. *' (time point).  Use this operator between your 'a', 'b' and 'c' vectors and your calculation of fishing.  For example, on your first line,
    d = (2/3)*a.*(sin(x))+(2/3)*b.*(sin(x-(2*pi/3)))+(2/3)*c.*(sin(x+(2*pi/3)));

    Don't forget to also change your output to a 1 d of DBL array variables.  You can do this by right-clicking on the output variable and selecting "Choose Data Type."

    Grant M.
    Staff software engineer | LabVIEW Math & Signal Processing | National Instruments

  • How to use an IF ELSE statement and the xdoxslt: get_variable together?

    First of all, I'm a big fan of this forum and I would like to thank the community for helping to make better the world BI Publisher.

    I'm trying to populate a table with a value of years of data with column = PRODUCT and row = month to DATE. Here's the catch, not every month will be given. Then here's where is my problem, I am not able to use an IF ELSE statement with an expression XDOXSLT:GET_VARIABLE so that if there is no given for this month the default value will be 0.

    Can someone help me find a solution to one of the attempts below or a method entirely new? Thank you!

    BP4 = numeric value of months with a DATE (more code to extract only the month DATE not included here)
    JAN1 = PRICE if there is data, 0 otherwise

    (1) I tried and it did not work:
    <? If: xdoxslt:get_variable($_XDOCTX,'BP4'), 01 xdoxslt:set_variable($_XDOCTX,_'JAN1',PRICE) then another end if xdoxslt:set_variable($_XDOCTX,_'JAN1',0)? >
    <? xdoxslt:get_variable($_XDOCTX,'JAN1')? >
    <? end if? >

    (2) I tried and it did not work:
    <? xdoxslt:IfElse (xdoxslt:get_variable($_XDOCTX,'BP4') = '01', xdoxslt:set_variable($_XDOCTX,_'JAN1',PRICE), xdoxslt:set_variable($_XDOCTX,_'JAN1',0))? >
    <? xdoxslt:get_variable($_XDOCTX,'JAN1')? >
    <? end if? >

    (3) I tried and it did not work:
    <? xdofx:If xdoxslt:get_variable($_XDOCTX,'BP4') = '01' xdoxslt:set_variable($_XDOCTX,_'JAN1',PRICE) then another end if xdoxslt:set_variable($_XDOCTX,_'JAN1',0)? >
    <? xdoxslt:get_variable($_XDOCTX,'JAN1')? >
    <? end if? >

    example of XML data:
    < ROW >
    < name > Craig Hernandez < / NAME >
    < DATE > 2013 - 01-01 T 00: 00:00.000 + 08:00 < / DATE >
    < PRICE > 31 < / PRICE >
    BPD of < PRODUCT > < / PRODUCT >
    < / ROW >


    -TRD

    Published by: 990965 on February 28, 2013 08:27

    >
    (1) I tried and it did not work:


    (2) I tried and it did not work:


    (3) I tried and it did not work:


    >
    so

    
    
    

    works for me, it's

  • Change the working directory of the MathScript node in the working directory of the VI in which the node is added

    Hello

    I want to automatically change the working directory of the node Mathscript in a VI in the working directory of the VI, while I don't have to specify every time where is my file ".m", as most likely, it will be in the same folder as the VI.

    Thank you

    Walid F. van

    Hi Wade,

    The following picture illustrates how to add the directory to your VI to MathScript search paths.

  • If the Else statement in the Validation of the values of other fields

    Thanks in advance for your help.

    Here is the statement:

    $3,000 (maximum)

    OR my remaining balance $ (field remaining balance)

    $ (total field)

    The maximum that the user can contribute is $ 3,000. If they enter a number greater than $3,000 for the balance, the total amount for this declaration should be $3,000. If they enter a number less than $3,000 for other balance, the total for that statement should be the number entered for the balance.

    I think I'm actually making it harder than it needs to be. I would like that the total field to evaluate user input in the field balance; If this number is large than.3, 000, the total is 3,000; If this is not the case, the field total is equal to the value entered in the balance field.

    Thanks again for your help.

    Gilad D (try67) wrote:

    There are two problems with your code:

    1. in a computation script we should apply the new value using event.value, not not not using the getField method.

    2. you must convert the value to 'Balance' a number explicitly.

    So the code should:

    var b = number (this.getField("Remaining_Balance").value);

    If {(b > 3000)

    Event.Value = 3000;

    } else event.value = b;

    I see, thank you Gilad.

  • State of the data nodes

    Hi all

    The customer (and other) nodes currently manages the State of all nodes?
    If so, what information and how do they know this information?
    Thank you

    893771 wrote:
    You said that the topology information are centralized. Where this information is centralized? At the level of the customer? Control only by replication group? Where do the admin process is? I never heard this process.

    The admin is a replicated process supported by a database of replicated (residing on Rep Nodes). Yes, it contains the topology. The topology is cached on the client and each of the nodes rep.

    Charles Lamb

  • If/Else statement with the drop-down list

    Hello!

    So I try to get the value of a hidden field in a form (which will be the basis for further calculations in the form) based on what is selected in a drop-down list. If "signed" is selected in the list, then value = the value entered in the field "TimeAddedToDate". If "unsigned" is selected, then the value = 0.

    This way I can properly do other calculations on the form.

    I'm having a problem with writing javascript, however. I was hoping that I would be able to understand reading some forums of javascript, but no luck so far.

    Any help would be greatly appreciated!

    It's my attempt failed:

    var time = this.getField("TimeAddedToDate").value;

    var Select = this.getField("ToDateOrderStatus").value;

    If (select == "Unsigned") event.value = 0;

    ElseIf ("select ==" Signed") event.value = time;

    Your script seems correct (assuming that the field names and the values of the)

    the options are that you used)... So what exactly does not work? You are

    get error messages in the console?

    On Friday, December 7, 2012 08:25, freelance_java_n00b

  • How can we use IF ELSE statement in the header Section

    Hi all

    I have obligation to indicate an address of invoice in the header section based on a special status, some body please share it is is it possible to use if elsewhere in the header section.


    Thanks in advance

    Thank you
    Pratap

    You can't place your if conditions inside the form fields in the header in Word. But you can directly type the tags in place.

    Concerning
    Charlotte

  • Is it possible to print the mathscript with color-coding text node?

    MathScript nodes lie down, I need to be able to make temporary annotations on paper.  Currently, the only way I can find to print the MathScript node is by screen capture and printing an image.

    While I can copy the text and put it in a word processing program, I would lose all the useful color coding.

    Y at - it a tip to copy as text and preserve color-coding?

    Download and install the notebook of the programmer.

    Copy all the text of the Mathscript node and paste it into Notepad to the programmer.

    In the menu bar - view - check syntax highlighting

    In the menu bar - display - regime change - select Matlab

    In the menu - Tools - Options - fonts and colors - bar you can select a larger font size

    (Although my vision is corrected to 20/10 and I have a lot of difficulty to read tiny fonts in the Mathscript node on a screen high resolution after a couple of hours.)

    This software is free and has a full set of features for serious programmers.

  • How to share a variable between the Mathscript Windows and a Mathscript node

    Hello

    I'm trying to share (just) a variable between the Mathscript Windows and a Mathscript node. I don't know why, but the use of the "global" Matlab function makes the mathscript node output formats change.

    I'm looking for a "Mathscript RT V9.0.1 module" as it may seem, there is. French technical support have some difficulty to find...

    Hi patrick33,.

    The code that you have attached should not report an error, so it seems that something has gone wrong with your installation of MathScript. My best guess is that it is the problem that is described in this knowledge base article. Your signature says that you use f3 patch, which is a good start. But the KB lists some other steps to take when you see errors about MathScript, impossible to compile. Can you try the procedure described in the article and let us know if that fixes the problem?

    Thank you

    jattas

    LabVIEW MathScript R & D

  • Suggestions for the MathScript Interactive window

    Hello world

    I just discovered LabView MathScript. It was a nice surprise as I am

    a used Matlab enthusiast. The interactive window is a great idea, however

    I miss a view things:

    (1) syntax Higlighting in the window "Script." It works in the MathScript node

    but for some strange reason, not in the interactive window.

    (2) line numbers in the "Script" window

    (3) the "F9" of Matlab function. If you mark a piece of code in Matlab and

    Press "F9" code is executed. Very useful for debugging.

    I just hope that someone from the MathScript developers is reading this.

    Thank you

    Ulf

    Hello

    Yes, we read we appreciate suggestions.  Numbers of syntax and the syntax line are features we know and we hope to add in a future version.  I was not aware of the F9 function, but we will consider it as well.

    Grant M.
    Staff software engineer | LabVIEW Math & Signal Processing | National Instruments

  • Why the mathscript well below matlab performance?

    Hi all

    I do the signal processing on a signal acquired with an ADC. The flow of information is roughly 10,000 x 1000 int8 Matrix per second. I'm trying to process the data at the same speed. Signal processing is done in a ".m" matlab file. The treatment is much to complicated to be coded in the G code.

    I have two choices:

    1. use matlab nodes

    2. using the Mathscript node.

    I've implemented the solution 1, but loses a lot of time just for the transfer of data between labview and matlab (matrix transfer ~ 10 MB). MATLAB is very quick to do signal processing. A faster version of this solution was to write the matrix in a bin file and pass the name of the file to matlab. It is faster (don't ask me why), but is not fast enough.

    Solution 2 sounds better, because as Mathscript is a native language, it is not necessary for the transfer. Prior to joining Mathscipt, I did the following test: run the same simple code on two solutions: calculate the fft of a matrix of 1024 x 1024 ten times (code attached).

    As a result, Matlab version node is 0. 5s compared to 1.6 s for the Mathscript node version.

    Why is the performance of mathscript so much less than the performance of the matlab node?

    If really Mathscript is much slower than Matlab, so I'm afraid I'll stay with node of matlab. Is there a better way to transfer data through files?

    Thanks in advance for your answers!

    You do not know, I can help you, but I found the same thing.

    I have a few guesses - do you use 64-bit Matlab? If so you may have noticed that MathScript runs under 32-bit LabVIEW.

    The other possibility is that Mathscript runs as a process integrated into LabVIEW, while if you use MatLab you use Simulink to communicate with Matlab in its own thread.

    Third option could simply be that Matlab is a commercial product that is much more optimized.

    Honest answer is that I don't know!

  • is it possible to use a file refnum as mathscript node entry

    Hello world

    I started using the LV and mathscript recently. A problem confuses me a lot.  It's

    Is it possible to use a file refnum as the entry or exit of the mathscript node? A picture is attached for your reference.

    Thank you very much!

    Gary

    What would you hope to do with the reference?  The Mathscript node is not a file of reading ability.  You must read the file and transmitting the data in the Mathscript node.

    EDIT: I was wrong.  You must use the functions fopen and fclose inside the MathScript node to be able to read a file inside.

  • mathscript node can work on arrays?

    on the help page Labview titled "Setting up the data type of the script node terminals", there is a line that says "because the MathScript node behaves differently that other nodes in script, you cannot change the data type of input terminals. Instead, if wire you a data type not supported for input on a node MathScript, LabVIEW converts the data type to a supported type or displays a cut wire. If LabVIEW converts the data type, a point constraint appears on the terminal where takes place the conversion. After that wire you an entry to a MathScript node, right-click the input terminal and select Show data of Type from the context menu to see the data type of the entry. »

    I don't understand this.

    I want to do math on arrays / vectors using mathscript. This means that I need input terminals in order to have a table data type.

    Say for example I have A [1 2 3 4 5] = (perhaps from a table of average data for 5 different channels) and say that I want to B = a ^ 2 (using the matlab syntax) - I can do this with a mathscript node?

    If this isn't the case, means that I can't do any math vector/matrix using the mathscript node? given that the whole point of matlab is to work on vectors and matrices, if mathscript node cannot do what it would also be a severe limitation.

    Dave

    Yes, you can use arrays in a MathScript node. Just create an entry on the node, give it a name and a value of table of wire to this entry.

Maybe you are looking for

  • If I do not use the home page by default, I start Firefox twice. I have all the modules and extensions disabled.

    I tried the setting of that my homepage to Google and Bing, but Firefox closes as soon as the page loads. He began a second time without any problem.

  • Memory p7-1154. Am I wrong?

    I want to verify that I have read the web page correctly. I have a p7-1154 that is 64-bit systems.  So this means that my computer can hold 16 GB of memory. Fix?   I now have 6 GB and try to understand the right parts to buy to update my computer.  A

  • Computer hangs when idle for 10 minutes +.

    Original title: Idle When my computer is idle for 10 minutes or more, it freezes and allow me to do anything.  I have to turn off the processor restart.  What do you suggest to fix this?

  • Question weird battery canon 60 d

    Hi, im as a canon 60 d and it came with a battery attached grip. I then bought a shoulder rig had to return the battery grip for the follow focus work. However, after the withdrawal of the battery grip and taking the batteries out of the handle and o

  • Editing an ssd for laptop

    I intend to exchange the hard drive in my laptop Acer Aspire 571-V3 with a Pro 840 Samsung 256 GB ssd. It is simple to do and someone there already done and can give me a help and advice?