0

I have 4 vectors, first threes are complex numbers and 4th one is summation of them.

I plot them with quiver successfully, however, I need to color 4th one as red. How can I color only 4th one to red?

% vectors I want to plot as rows (XSTART, YSTART) (XDIR, YDIR)
rays = [
  0 0   real(X1) imag(X1) ;
  0 0   real(X2) imag(X2) ;
  0 0   real(X3) imag(X3) ;
  0 0   real(SUM) imag(SUM) ;
] ;

% quiver plot
quiver(rays( :,1 ), rays( :,2 ), rays( :,3 ), rays( :,4 ));

% set interval
axis([-30 30 -30 30]);

or shall i use plotv ? https://www.mathworks.com/help/nnet/ref/plotv.html

1 Answer 1

1

The handle returned by quiver function does not allow to access to each single element in order to change its properties, in this case, the colour.

A possible work around, although not exactly elegant, could be to:

  • plot the quiver for the whole set of data
  • remove from the axes the u, v, x and y data of the element you want to change the colour
  • set hold on
  • plot again the quiver for the whole set of data
  • remove from the axes the u, v, x and y data of the element you do not want to change the colour
  • set the desired colour to the remainig item

A possible implementation of the proposed approach could be:

% Generate some data
rays = [
  0 0   rand-0.5 rand-0.5 ;
   0 0  rand-0.5 rand-0.5 ;
   0 0  rand-0.5 rand-0.5 ;
] ;
rays(4,:)=sum(rays)

% Plot the quiver for the whole matrix (to be used to check the results
figure
h_orig=quiver(rays( :,1 ), rays( :,2 ), rays( :,3 ), rays( :,4 ));
grid minor
% Plot the quiver for the whole matrix
figure
% Plot the quiver for the whole set of data
h0=quiver(rays( :,1 ), rays( :,2 ), rays( :,3 ), rays( :,4 ));
% Get the u, v, x, y data
u=get(h0,'udata')
v=get(h0,'vdata')
x=get(h0,'xdata')
y=get(h0,'ydata')
% Delete the data of the last element
set(h0,'udata',u(1:end-1),'vdata',v(1:end-1),'xdata', ...
   x(1:end-1),'ydata',y(1:end-1))
% Set hold on
hold on
% Plot again the quiver for the whole set of data
h0=quiver(rays( :,1 ), rays( :,2 ), rays( :,3 ), rays( :,4 ));
% Delete the u, v, x, y data of the element you do not want to change the
% colour
set(h0,'udata',u(end),'vdata',v(end),'xdata', ...
   x(end),'ydata',y(end))
% Set the desired colour to the remaining object
h0.Color='r'
grid minor

enter image description here

Hope this helps,

Qapla'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.