# Send one Matlab variable output and use it as an input for in my UR

**URL:** <https://forum.universal-robots.com/t/send-one-matlab-variable-output-and-use-it-as-an-input-for-in-my-ur/29449>\
**Category:** General Application Help: How do I?\
**Created:** [July 8, 2023, 10:17am UTC](https://forum.universal-robots.com/t/send-one-matlab-variable-output-and-use-it-as-an-input-for-in-my-ur/29449 "2023-07-08T10:17:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![anon63586213](https://avatars.discourse-cdn.com/v4/letter/a/a8b319/32.png) [@anon63586213](https://forum.universal-robots.com/u/anon63586213)\
**Post date:** [July 8, 2023, 10:17am UTC](https://forum.universal-robots.com/t/send-one-matlab-variable-output-and-use-it-as-an-input-for-in-my-ur/29449/1 "2023-07-08T10:17:33Z")

</div>

Hello. I am currently working with a Universal Robot using the PolyScope user interface. I need this robot to communicate with my Matlab code which does image processing and then classifies the image to either category A, B or C. I have created a variable on the Matlab code called “imageSignal” which returns either 1, 2 or 3 depending on the category. What I need is to send this variable to the robot in order for it to know what to do in case imageSignal =1, 2 or 3.

I have read about RTDE and using TCP/IP communication but I do not know how to do it with Matlab or where to start.

Could any of you help me?

---

<div class="post-metadata">

**Author:** ![eric.feldmann](https://avatars.discourse-cdn.com/v4/letter/e/94ad74/32.png) [@eric.feldmann](https://forum.universal-robots.com/u/eric.feldmann)\
**Post date:** [July 10, 2023, 3:14pm UTC](https://forum.universal-robots.com/t/send-one-matlab-variable-output-and-use-it-as-an-input-for-in-my-ur/29449/2 "2023-07-10T15:14:00Z")

</div>

> **[Modbus Communication
- MATLAB & Simulink](https://www.mathworks.com/help/icomm/modbus.html)**
>
> Communicate with Modbus servers to access controllers, probes, and other instruments

Maybe take a look at Modbus communication? I’ve had really good success with this on the UR robot in the past. You should be able to just write this variable to one of the general purpose integer registers on the UR (signal list here: [https://s3-eu-west-1.amazonaws.com/ur-support-site/16377/ModBus%20server%20data.pdf](https://s3-eu-west-1.amazonaws.com/ur-support-site/16377/ModBus%20server%20data.pdf))

Specifically, writing to register 128 should make your value easily accessible on the UR side by looking at modbus gp register 0.  
Looks like this MATLAB command might do the trick:

 ![image](https://us1.discourse-cdn.com/flex020/uploads/universal_robots/original/2X/2/298e4ad79ef52a2d1f40218cc1a1e29dc219b435.png)

Then you just have to setup a quick Modbus server on the teach pendant, which takes about 3 seconds. Just assign it an IP address that’s on the same subnet as whatever your matlab machine is on.
