Scatter with colour-coded markers (matrix)
11 views (last 30 days)
I want to do a scatter with several points x [1303 x 382] and y [1303 x 382]. Each of the points has a different velocity, saved in the matrix velo [1303 x 382].
When I try to do it with scatter(x,y,10,velo), there is an error:
"Color must be one RGB triplet, an m-by-3 matrix of RGB triplets with one color per scatter point, or an m-by-1 vector with one value per scatter point."
How do I do a plot with the points with colour-coded markers based on the velocity?
Thanks for your help!
Walter Roberson on 5 Jun 2022
scatter(x(:), y(:), 10, velo(:))
You might potentially also want to add a caxis() call, if you want to map velocities to consistent colors.
Image Analyst on 5 Jun 2022
Edited: Image Analyst on 5 Jun 2022
% Initialization Steps.
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
% clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
fontSize = 20;
% Create sample data because the original poster forgot to.
rows = 3; % or 1303
columns = 382;
markerSize = 15;
x = rand(rows, columns);
y = rand(rows, columns);
numElements = numel(x)
% Make velocity in the range 0-15.
velo = 15 * rand(rows, columns);
% Create a colormap based on velo.
% First sort velo
[sortedVelo, sortOrder] = sort(velo(:), 'ascend');
numDistinctColors = numel(velo)
% Create a generic colormap.
cmap = jet(numDistinctColors);
% Now each row in cmap has c color corresponding to the velo value.
% Plot a scatterplot
scatter(x(:),y(:), markerSize, cmap, 'filled')
% Show the colorbar as a guide to what color is what velocity.
minVelocity = 0
maxVelocity = max(velo(:))
title('Color Coded Velocity', 'FontSize',fontSize)
If you have any more questions, then attach your data and code to read it in with the paperclip icon after you read this: