The receive function will only ever receive a single message, and returns immediately upon receiving that message. It is not a replacement for echo. The "10" in your example is the timeout - if a message is not received within 10 seconds it will error. Generally, I recommend only using receive once, when you need to ensure that the subscriber has gotten a message before you enter into your main control loop if you are going to be working on the LatestMessage property of the subscriber. This design pattern would look like this:
sub = rossubscriber(topic, type);
That design pattern is useful if you need to execute on a regular cadence with the most up-to-date data (like a camera image), but don't necessarily need to process all messages sent to the subscriber. This pattern is frequently used in conjunction with rosrate to set the cadence. The other main design pattern is to process every message in the subscriber callback. This is useful if every message needs to be processed or else data will be lost. The design pattern typically looks like this:
cb = @(src, msg) myCallback(src, msg, additional, parameters);
sub = rossubscriber(topic, type, 'NewMessageFcn', cb);
function myCallback(src, msg, additional, parameters)
You might even see a combination of these patterns, where one slow subscriber sets the cadence, and then the most recent information from other subscribers is used at that time. That might look something like this (for a more application-focused example):
gpsSub = rossubscriber("/gps", "sensor_msgs/NavSatFix");
imuSub = rossubscriber("/imu", "sensor_msgs/Imu");
posePub = rospublisher("/estimated_position", "geometry_msgs/PoseStamped");
cameraCallback = @(src, msg) cameraUpdateEKF(msg, gpsSub, imuSub, posePub);
cameraSub = rossubscriber("/camera", "sensor_msgs/Image", "NewMessageFcn", cameraCallback);
function cameraUpdateEKF(imageMsg, gpsSub, imuSub, posePub)
gpsMsg = gpsSub.LatestMessage;
imuMsg = imuSub.LatestMessage;
poseMsg = updateEKF(imageMsg, gpsMsg, imuMsg);
I would suggest thinking about what your application requires and looking into one of these design patterns for use.
-Cam