How to add colourmap to 2D vectorplot created by using quiver

21 visualizaciones (últimos 30 días)
Hello all,
I have created 2D vector plot by using quiver i.e( quiver (x,y,u,v)), i am getting vecrot plot of 20*9 ( totally 180 vectors) . i have to add colours to this vector plot where colour of the plot represents the magnitude of vector at that index along with vectors in the plot with colour bar the end. kindly help me in this and any proper sources for learning the matlab as i am a beginner.
Thank in advance

Respuestas (2)

Shubham Rawat
Shubham Rawat el 25 de En. de 2021
Hi HariKrishna,
You may use this file to solve your problem:
You can download this file and run into your MATLAB. This contains a function quiverwcolorbar, which can colour the vector plot according to their vector magnitude.
Hope this helps!

darova
darova el 4 de Feb. de 2021
Try this example
clc,clear
[x,y,z] = peaks(20); % generate data
[u,v] = gradient(z,1); % create u and v vectors
h = quiver(x,y,u,v); % display standard quiver
% extract each arrow separately
c = get(h,'children');
x1 = get(c(2),'xdata'); % arrow body
y1 = get(c(2),'ydata');
x2 = get(c(3),'xdata'); % arrow head
y2 = get(c(3),'ydata');
cmap = jet(200); % generate 200 colors
% color arrows according to Z values
F = scatteredInterpolant(x,y,z);
zmin = min(z(:));
k = max(z(:)) - min(z(:));
for i = 1:3:length(x1);
ii = (F(x1(i),y1(i))-zmin)/k*199; % scale Z value (0-199)
ii = round(ii)+1; % index of color
line(x1(i:i+2),y1(i:i+2),'color',cmap(ii)) % body
line(x2(i:i+2),y2(i:i+2),'color',cmap(ii)) % head
end

Categorías

Más información sobre Elementary Polygons en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by