Change colors of arrows in quiver3

37 views (last 30 days)
Hi,
I used quiver3 to plot some wind measurements at three different heights. I would like to change the color for the bottom, middle and top arrows to red, green and blue respectively. I would be grateful if you can help me with that.
I only used quiver3 beacuse I knew the function. Please suggest other functions if they would a better suite for this purpose.
quiver3(x3d,y3d,z3d,cell2mat([Vx_NB_B Vx_NB_M Vx_NB_T]),cell2mat([Vy_NB_B Vy_NB_M Vy_NB_T]),zeros(1,90))
  1 Comment
Scott MacKenzie
Scott MacKenzie on 27 Apr 2021
How about this:
h1 = quiver3( . . . ); % code for top arrows
h1.Color = 'r'; % red arrows
hold on;
axis([0 80 0 200 0 9]);
h2 = quiver3( . . . ); % code for middle arrows
h2.Color = 'g'; % green arrows
h3 = quiver3( . . . ); % code for bottom arrows
h3.Color = 'b'; % blue arrows

Sign in to comment.

Accepted Answer

Scott MacKenzie
Scott MacKenzie on 30 Apr 2021
Edited: Scott MacKenzie on 30 Apr 2021
Faraz's primary concern is controlling the color in each stratum of the plot. I think this is close to the answer sought:
n = 500;
bottomStratum = [10 20];
middleStratum = [40 60];
topStratum = [80 90];
x = randi(100, 1, n);
y = randi(100, 1, n);
z1 = randi(bottomStratum, 1, n);
z2 = randi(middleStratum, 1, n);
z3 = randi(topStratum, 1, n);
u = x .* rand(1, n);
v = y .* rand(1, n);
w1 = z1 .* rand(1, n);
w2 = z2 .* rand(1, n);
w3 = z3 .* rand(1, n);
% bottom arrows
quiver3(x, y, z1, u, v, w1, 'color', 'r');
hold on;
axis([0 100 0 100 0 100]);
% middle arrows
quiver3(x, y, z2, u, v, w2, 'color', 'g');
% top arrows
quiver3(x, y, z3, u, v, w3, 'color', 'b');

More Answers (1)

Pratheek Punchathody
Pratheek Punchathody on 30 Apr 2021
You can use the following code as reference for changing the color of the arrows using the "Color property in quiver3()" function.
load wind %loading the data
X = x(5:10,20:25,6:10);
Y = y(5:10,20:25,6:10);
Z = z(5:10,20:25,6:10);
U = u(5:10,20:25,6:10);
V = v(5:10,20:25,6:10);
W = w(5:10,20:25,6:10);
quiver3(X,Y,Z,U,V,W,'color','r'); %'color' Name-Value pair will help to change the color of the arrow
axis equal
Below shows the output obtained from the above code.
Hope this helps..

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!