Simple Subscriber

In the following example we first create Matlab function listener which we subscribe to topic chatter. Our Matlab function will log incoming message (std_msgs/String) to file ~/ListenerLog.

The Matlab function (located in package: clopema_matlab_tutorials/matlab):

function listener(ros_in)
%Automatically generated function for ROS (Robot Operating System) implementation in matlab
% in commented variable ros_in (overlaying input) the default values for input message are set 
    %ros_in = struct('data', '');
    cd ~;
    fid = fopen('ListenerLog','a');

Subscribe Matlab function to topic chatter arguments are:
  • Message type
  • Topic name
  • Matlab function name (without extension)
rosrun clopema_matlab std_msgs/String chatter listener