# Create Linear and Polar Plots with LabVIEW MathScript Node

Updated Oct 16, 2020

## Environment

### Software

• LabVIEW
• LabVIEW MathScript Module
Note: NI does not recommend LabVIEW MathScript Module functions for new designs. See www.ni.com/migratemathscript for information and recommended alternatives.

LabVIEW also allows you to create .m files and work with text-based math using the MathScript Node. Script nodes combine text-based .m files with traditional LabVIEW graphical programming. Script nodes are resizable text-entry regions you can add to LabVIEW block diagrams. For a familiarizing yourself with the MathScirpt Node, follow the Using MathScript Node in LabVIEW tutorial.

This tutorial shows you how to build a more complicated VI that displays an RF antenna pattern for a dish antenna in linear (XY) and polar plots. The example shows how to build a custom user interface to add interactivity to an algorithm you define in a script in a .m file using a MathScript Node. The example adds a control input to set the amplitude/lambda input parameter of the algorithm.

This tutorial requires LabVIEW and MathScript Module. Although familiarity with .m syntax is preferable, it is not required that you have MATLAB™ installed on your machine.

### Create the User Interface

1. Launch LabVIEW and open a new VI.
2. Right-click on the front panel to add a Numeric >> Knob control. You will use this control to set the size and wavelength of the RF antenna.
3. Change the name of the Knob control to Amplitude/lambda.
4. Right-click on the front panel to add a Graph >> XY Graph
5.  Right-click on the front panel to add a Graph >> Controls >> Polar Plot Indicator. You will use this indicator to show the RF antenna pattern as a function of the angle.
6. Switch to the block diagram and locate the controls and indicators you created on the front panel. Organize the block diagram with the control (knob) on the left side and the indicators (the polar plot indicator and the XY graph) to the right side of the block diagram.

1. Right-click on the block diagram to add a Structures >> MathScript Node.
2. Copy and paste the following script into the MathScript Node. This script processes the gain of the antenna at different angles.
% Create angle vector in radians
theta = linspace(-pi/2,pi/2,1000);
u = 2*pi*a*sin(theta);

% initialize matrix
E = ones(size(u));

% Get index of non-zero values
i = find(u);

% Evaluate Antenna pattern equation
E(i) = pi*a^2*abs(2*besselj(1,u(i))./(u(i)));

% change theta to degrees units for polar plot
Out=theta.*180./pi;
1. Right-click the left border of the MathScript Node and select Add Input from the shortcut menu.
2. Add a to the input label, creating the variable for the script.
3. Connect the Amplitude/lambda control to the a input.
4. Right-click the right border of the MathScript Node and select Add Output from the shortcut menu.
5. From the output list available, select Out. This variable represents the angle vector for plotting purposes.
6. Right-click the Out output terminal and select Choose Data Type >> 1D-Array >> DBL 1D from the shortcut menu to specify the data type of the Out output variable.
7. Repeat the steps 12 through 14 for the variable. This variable represents the gain output at different angles.
8. Right-click to add a Cluster, Class, & Variant >> Bundle function to the block diagram.
9. Add Out and E respectively to the Bundle function; then wire the output of Bundle of the XY graph. This becomes the X and Y components of the XY graph as shown in the following block diagram. ### Configure the Polar Plot

1. Add a Structures >> For Loop to the block diagram.
2. Place a Bundle function inside the For Loop.
3. Connect the Output and E inputs to the input terminals of Bundle
• The squares in the border of the For Loop indicate the loop is set to auto index, or process each input element separately.
4. Wire the Bundle output to the data array input of the Polar Plot with Point Options VI. 1. On the Polar Plot VI, right-click the Polar attributes input and select Create Control from the shortcut menu.
2. Switch to the front panel and set the Amplitude/lambda control to 2.
3. Configure the parameters of the polar plot:
• Show a Log scale by pressing the log? button which is False by default
• Display only the right half of the plot in visible section input.
At this point, you can test your VI by pressing Run. You will see the XY graph and polar plot data appear, and the VI will stop.
To run continuously, add a While Loop with Button around your block diagram code.
In the end, you will have created an XY graph and polar plot using the analysis capabilities of text-based code in the MathScript Node paired with the ease of graphical communication of LabVIEW.
{"ft_lang_label":"__label__en","ft_lang_prob":0.7303533,"math_prob":0.6706641,"size":3307,"snap":"2020-45-2020-50","text_gpt3_token_len":748,"char_repetition_ratio":0.13866182,"word_repetition_ratio":0.05752961,"special_character_ratio":0.23677048,"punctuation_ratio":0.09119011,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9667946,"pos_list":[0,1,2,3,4,5,6],"im_url_duplicate_count":[null,null,null,null,null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2020-11-28T20:43:12Z\",\"WARC-Record-ID\":\"<urn:uuid:41f1db7f-5a80-4473-9eb6-f9058abf1668>\",\"Content-Length\":\"46858\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:179485d9-1a37-4774-aa0c-4c412866cc74>\",\"WARC-Concurrent-To\":\"<urn:uuid:6da778d1-63e3-4461-baad-2805610fcf30>\",\"WARC-IP-Address\":\"13.109.151.121\",\"WARC-Target-URI\":\"https://knowledge.ni.com/KnowledgeArticleDetails?id=kA03q000000x3J9CAI&l=en-US\",\"WARC-Payload-Digest\":\"sha1:LOO32VJBY4KLRBYXKBMTSFZLCIVFYV6O\",\"WARC-Block-Digest\":\"sha1:PVGWBBEAGNQ5VVXLJUABSN65K2R7ZJRL\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2020/CC-MAIN-2020-50/CC-MAIN-2020-50_segments_1606141195745.90_warc_CC-MAIN-20201128184858-20201128214858-00208.warc.gz\"}"}