Example Code

String to Complex Number

Products and Environment

This section reflects the products and operating system used to create the example.

To download NI software, including the products shown below, visit ni.com/downloads.

    Software

  • LabVIEW

Code and Documents

Attachment

Overview: The VI converts the string format with complex numbers to complex number format.


Description:

Takes a string input in one of the following formats:

x+iy; -x+iy; x-iy; -x-iy; x+jy; -x+jy; x-jy; -x-jy;

where x and y are numbers.

The VI then splits the sting into three strings: the real part (including the middle operator), the i or j, and complex part.  Next, the "+" or "-" case is selected by extracting the last element of the string containing the real part.  The extraction is done by determining the length-1 of the string and making this value the offset for String Subset, which leaves just the operator as the substring for the case selector.  Inside the cases, the string are converted to double precision numbers and combined into a complex number.  The "-" case converts the complex part to a negaitve number by subtracting it from zero.


Steps to Implement or Execute Code:

1. Insert string input.
2. Run the VI.
3, Write down the result from Complex Number.


 Additional Information or References:

 

String to Complex Number FP.png

 

String to Complex Number sn.png

 

The user needs to select whether "i" or "j" is used when writing the complex number.


**This document has been updated to meet the current required format for the NI Code Exchange.** 

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Comments
Knight of NI
Knight of NI
on

I'm not sure why the author felt it necessary to change the format from the standard LabVIEW format of "a+bi" to "a+ib". Wolfram?

Shown below is a simple VI that uses the "a+bi" that LabVIEW uses.

UTIL - String - String to Complex (CDBL)_BD.png