MATLAB Examples

Read A ROS Image Message In Simulink®

This example requires Computer Vision System Toolbox® and Robotics System Toolbox®

Start a ROS network.

Initializing ROS master on http://bat7778maci:59557/.
Initializing global node /matlab_global_node_19757 with NodeURI http://bat7778maci:59561/

Load sample messages to send including a sample image message, img. Create a publisher to send an ROS Image message on the '/image_test' topic. Specify the emssage type as '/sensor_msgs/Image'. Send the image message.

pub = rospublisher('/image_test','sensor_msgs/Image');

Open the Simulink® model for subscribing to the ROS message and reading in the image from the ROS.

Ensure that the Subscribe block is subscribing to the '/image_test' topic. In the menu under Tools > Robot Operating System > Manage Array Lengths, verify the Data array has a maximum length greater than the sample image (921,600 pixels).


Run the model. The Video Viewer should show the sample image.

Stop the simluation and shut down the ROS network.

Shutting down global node /matlab_global_node_19757 with NodeURI http://bat7778maci:59561/
Shutting down ROS master on http://bat7778maci:59557/.