From GridLAB-D Wiki

Template:NEW30
This **How To** describe how to create a plot using Matlab®'s hist command.

## System requirements

- Hassayampa (Version 3.0)
- You must be using a version of GridLAB-D that support the link directive.
- Matlab link
- You must have a version of Matlab that supports the Matlab external interface engine and the hist command.

Suppose you have a GLM file named *my_plot.glm* that defines a trivial object *test* as follows:

clock { starttime '2001-01-01 0:00:00'; stoptime '2001-01-02 0:00:00'; } class test { random x; } object test { name my_test; x "type:normal(0,1); refresh:1min; integrate"; }

## Step 1 - Link GLM to Matlab using a link control file

Add the link directive to your GLM file:

link matlab_plot.link;

## Step 2 - Create the link control file

Create the link control file using the following commands

target matlab workdir hist window show output 100000 global object export my_test.x x on_init q=zeros(1000,1); n=1; ans=GLD_OK; on_sync if(n<1000) q(n)=x; ans=TS_NEVER; on_term hist(q); saveas(gcf,'q.png'); ans=GLD_OK;

## Step 3 - Run GridLAB-D

C:\GridLAB-D> gridlabd my_plot.glm ... perhaps some output is displayed C:\GridALB-D>

## Step 4 - View the PNG file

Open a file explorer, go the **hist** folder, and double-click on the PNG file.