MATLAB: How to plot 2D figure (x,y) and add 3rd axis (velocity) by variation the color through the path

MATLABplotting

I am trying to plot a 2D figure (x,y) and add 3rd axis (velocity) by variation the color through the path. I did code and add related colorbar. In fact I would like to show each point by corresponding velocity value by changing color that colorbar already shows. However, I don't have any idea how I can vary the velocity. My solution that I already used not show the exact velocity values. I also attached the data. Any idea? Thanks in advance
Elnaz
close all
clear all
clc
%%
load data3
x =data (:,1); %X
y =data (:,2); %Y
z =data (:,3); %Mean velocity
z_min=min(min(z));
z_max=max(max(z));
x_min=min(min(x));
x_max=max(max(x));
y_min=min(min(y));
y_max=max(max(y));
dt=(6.95:0.05:19.5);
figure % new figure
title ('Trajectory of Particles')
grid on
xlabel('X (m)')
yyaxis right
plot(x,y,'k--o','LineWidth',2,'MarkerEdgeColor','r','MarkerFaceColor','none');
ylabel('Y(m)')
yyaxis left
plot(x,z,'w');
ylabel('Mean Velocity(m/sec)')
c = colorbar;
c.Label.String = 'Mean Velocity(m/sec)';
caxis([z_min z_max]);

Best Answer

One possibility is to change the second plot call to scatter, since the scatter functions allow color-coded markers.
Try this:
figure % new figure
title ('Trajectory of Particles')
grid on
xlabel('X (m)')
yyaxis right
plot(x,y,'k--o','LineWidth',2,'MarkerEdgeColor','r','MarkerFaceColor','none');
ylabel('Y(m)')
yyaxis left
scatter(x,y, 40, z, 'filled'); % <— CHANGE THE SECOND ‘plot’ CALLL TO ‘scatter’
ylabel('Mean Velocity(m/sec)')
c = colorbar;
c.Label.String = 'Mean Velocity(m/sec)';
caxis([z_min z_max]);
Here, the ‘z’ value colors the scatter markers. You will probably have to experiment with this to get the result you want. See the documentation on the scatter (link) function for more information on it.
EDIT —
Adding the plot:
How I can plot 2D figure (x,y) and add 3rd axis (velocity) by variation the color through the path - 2019 01 02.png