Home > Blockchain >  Change Color for Vector Arrows in Matlab Using Quiver Function
Change Color for Vector Arrows in Matlab Using Quiver Function

Time:09-23

I have the following code on Matlab

x = [0.49015734, 0.04615336, 0];
y = [0.76897085, 0.8420684, 0];
z = [0.41040173, 0.5373925, 0];

StainVector=[x; y; z];
starts = zeros(3,3);
ends = StainVector';

q=quiver3(starts(:,1), starts(:,2), starts(:,3), ends(:,1), ends(:,2), ends(:,3),...
    'Color', StainVector(:,1));
axis([0 1 0 1 0 1])
title('Test Plot')
xlabel('x')
ylabel('y')
zlabel('z')

which yields a 3D plot with two vector arrows (a third one is suppressed because it starts and ends at 0,0,0.) How can I change the color of an arrow to an RGB value, and the color of the other arrow to another RGB value?

Here's the image I get from my code: enter image description here

CodePudding user response:

Unfortunately I only see the option with a loop, since the color option is applied to all arrows within the quiver call.

as an example

colMap = eye(3);  % RGB Matrix with your colors

for idx = 1:size(starts,1)
    q=quiver3(starts(idx,1), starts(idx,2), starts(idx,3), ends(idx,1), ends(idx,2), ends(idx,3), ...
        'Color', colMap(idx,:));
    hold on
end
  • Related