How to plot 3D data on 2D coordinate system with 3rd item indicated by color scale

7 views (last 30 days)
Hey Guys, I've been trying to make a map which has indicators for the velocity that has been measured. I've succeeded in writing a file that plots the points where measurements were done on the already existing map. I don't know however how i can plot the 3rd variable, the velocity, on there as well. The velocity should be indicated by the color of the points (a scale from black to white i'm thinking).
The .m file is included.
The velocity variable is 'U'.
It would even be more awesome if the directional indicators u and v could be included as well (respectively east and north velocity). So to create vectors for the velocity.
If someone could help me out with the colorscale and plotting U I'd be very greatful!
  3 Comments
Yuri Engelshoven
Yuri Engelshoven on 1 Mar 2015
I've solved the issue. Thanks for the help. For someone in the future with the same problem, the working code is included.
if true
clear all
close all
clc
datdir='F:\Studie_&_Werk\Civiele_Techniek\BEP\Svasek\ASCII data\ADCP stroming\120331\';
x=[];y=[];t=[];u=[];v=[];U=[]
xyz=load('F:\Studie_&_Werk\Civiele_Techniek\BEP\Svasek\Survey\Cdam_120331_0930.xyz');
figure
plcolpoints(xyz);
hold on
files = dir([datdir 'MV2*']);
for j=1:length(files)
fid = fopen([datdir files(j).name]);
C=textscan(fid,'%f %f %f %f %f %f %f %f %f %f %f','Headerlines',26);
fclose(fid);
x=[x;C{1}];
y=[y;C{2}];
t=[t;datenum(num2str(C{4}) ,'yyyymmdd')+datenum(num2str(C{5}),'HHMMSS')-734869];
u=[u;C{7}];
v=[v;C{8}];
U=[U;C{9}];
u(u==999.999)=0
v(v==999.999)=0
U(U==999.999)=0.001
S=repmat([4],length(U),1);
C=repmat([U/2,U/2,U/2],1,1);
scatter3(x,y,U,S,C)
end

Sign in to comment.

Accepted Answer

Stephen23
Stephen23 on 1 Mar 2015
Edited: Stephen23 on 1 Mar 2015
Use quiver to plot vector arrows on a 2D plot, or quiver3 to plot arrows in a 3D plot.
You can change their colors, marker size or any other properties by setting the quiver series properties.
You should learn to navigate MATLAB's documentation, then you can find functions by yourself. When you open the documentation for quiver, have a look on the left-hand side of the page: there you will see the Contents. The currently opened section is MATLAB -> Graphics -> Vector Fields -> Functions, and you can also see some other functions for plotting vectors: these include feather, compass, streamslice, and streamline. And note that you can browse for other kinds of plots, such as Line Plots, Polar Plots, Contour PLots, etc, or even for different operations in MATLAB!
Spending ten minutes learning to navigate the contents, and getting comfortable using the documentation will make using MATLAB much easier, faster and enjoyable.
  2 Comments
Yuri Engelshoven
Yuri Engelshoven on 1 Mar 2015
Edited: Yuri Engelshoven on 1 Mar 2015
Thanks for your advice Stephen. I had already tried to solve my issue using feather and surf but unfortunately errors keep appearing. In using surf(x,y,z) z needs dimensions [x*y]. But it doesnt have that... Is there a way to use surf for only a small amount of grid points on a larger grid?
Stephen23
Stephen23 on 1 Mar 2015
Edited: Stephen23 on 1 Mar 2015
At the bottom of the surf documentation page is a link entitled Surface Plots of Nonuniformly Sampled Data. If you click on the link you will find a page that explains how you can plot data when Z is not a matrix. Alternatively, if you do not need a surface plot, you could try scatter3 or something similar.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!