2017-02-26 30 views
0

我有4個載體,第一個三位是複數,第四個是它們的總和。matlab中的着色顫動矢量

我用箭頭成功繪製了它們,但是,我需要將第四個顏色作爲紅色着色。我怎樣才能使第四個顏色變紅?

% 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]); 

或者我應該使用plotv嗎? https://www.mathworks.com/help/nnet/ref/plotv.html

回答

1

handle返回quiver函數不允許訪問每個單個元素,以便更改其屬性,在這種情況下,顏色。

一個可能的解決辦法,雖然不完全是優雅的,可能是:

  • 情節顫動整個數據集的
  • 從軸取出的uvxy數據元素你想改變顏色
  • 設置hold on
  • 情節再次quiver對整個數據集
  • 從軸取出uv,元素的xy數據,你不想改變顏色
  • 所需的顏色設置爲remainig項目

一可能實施方案提出的方法可能是:

% 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

希望這會他lps,

Qapla'