# Lesson 1. Creating a "Hello World" User Measurement Script

In this MATLAB example, you'll learn how to create the simplest measurement possible to prove your Infiniium / MATLAB environment. After you finish this lesson, continue with Lesson 2.

## Procedure

1. Make sure that you have fulfilled the basic requirements for MATLAB and that you are familiar with the environment for MATLAB scripts.
2. Copy the following XML listing into a text editor. Name the file HelloWorld.xml and save it in Infiniium's user measurements folder (\Documents\Keysight\Infiniium\User Measurements).

HelloWorld.xml
Drag the mouse over this listing, enter Ctrl-C to copy, and paste it into your text editor.
<?xml version="1.0" encoding="utf-8"?> <Measurement xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <Script>HelloWorld.m</Script> <Name>Hello World!</Name> <!-- <Icon>MyPicture.png</Icon> --> <ValidType>Wave</ValidType> <MeasurementType>1 Source</MeasurementType> </Measurement> |
The <Icon> element is optional. This element allows you to place a picture on your user operator icon.
Example measurement button without <Icon> element | Example measurement button with <Icon> element

3. Copy the following script into MATLAB's editor. Save your script file in Infiniium's user measurements folder (\Documents\Keysight\Infiniium\User Measurements) and name it HelloWorld.m. Color in the following script identifies:

- That Output variables should normally be initialized in your scripts.
- The input waveform SrcData is missing as the script simply tests if a value can be returned.
- That output variable, Result, returns a pretend measurement value, 4.2! This is a very simple script that doesn't even calculate a result.

HelloWorld.m
Drag the mouse over this listing, enter Ctrl-C to copy, and paste it into the MATLAB editor.
    % These values need to be set by the script.
    % Set Status to Correct only when Result is computed.
    Result = 0.0;
    Status = 'Invalid';
    ErrorMsg = '';
    Units = 'dB';
    % Compute Result
    Result = 4.2;
    Status = 'Correct';

Do not use spaces or hyphens when selecting a filename for your script.

4. Make a Single acquisition.
5. Choose Measure > Measurements....
6. At the bottom of the Add Measurements dialog box, click User Defined Wave Measurements....
7. In the User Measurement Setup dialog box, select an available tab.
8. Click Browse... and select your XML configuration file, HelloWorld.xml.
9. Add the measurement. Click on your new Hello World! measurement button.
10. In the User Meas dialog box, select the Signal and measurement Region; then, click Apply.
11. In the Results content window, notice that the Hello World! measurement result of 4.2 dB is reported.