How to assign specific colors to every quiver?

조회 수: 15 (최근 30일)
Thomas Schlatter
Thomas Schlatter 2019년 10월 17일
댓글: Thomas Schlatter 2019년 10월 17일
Hi,
I would like to assign specific colors to my quiver plot. There are 13 quivers and i would assign to it 13 colors to reproduce it in a further iteration.
So my matrix A is [13x2], u and v are [13,1] and the color matrix col is [13x3].
The code should looke somehow like this but quiver doesn't accept a color matrix:
h(t)= quiver(A(:,1),A(:,2),u,v,1000,'color',col);
Is there a simple solution for this problem?
Thank you!

답변 (2개)

darova
darova 2019년 10월 17일
You can manually assign color to each vector
clc,clear
[x,y] = meshgrid(0:0.2:2,0:0.2:2);
u = cos(x).*y;
v = sin(x).*y;
h = quiver(x,y,u,v);
% exctract data of vectors
h1 = get(h,'children');
x1 = get(h1(1),'xdata'); % arrowline
y1 = get(h1(1),'ydata');
x2 = get(h1(2),'xdata'); % arrowhead
y2 = get(h1(2),'ydata');
pause(0.2)
k = 0;
hold on
for i = 1:length(x1)/3
color = rand(1,3);
ii = (1:3) + (i-1)*3;
plot(x1(ii),y1(ii),'color',color)
plot(x2(ii+k),y2(ii+k),'color',color)
k = k + 1;
end
hold off
  댓글 수: 3
darova
darova 2019년 10월 17일
What length of H vector?
Thomas Schlatter
Thomas Schlatter 2019년 10월 17일
H is a '1x1 Quiver'.

댓글을 달려면 로그인하십시오.


Guillaume
Guillaume 2019년 10월 17일
I can't remember if quiver did have children before R2014b (when the graphics system changed drastically) but since R2014b it does not (unless it has datatips, in which case the children are just the datatips).
It's not possible to access the individual arrows in a single quiver plot, at least in a documented way, and therefore it's not possible to change the colour of individual arrows.
You're left with making a single quiver call for each arrow (which may be slow) or searching on the FileExchange for an alternative implementation, e.g. this, this or this and probably more. Note that some of these functions (e.g. the first one) may use unsupported ways of accessing the quivers, which may not work in future matlab versions.
  댓글 수: 1
Thomas Schlatter
Thomas Schlatter 2019년 10월 17일
Okey, yes I use R2019a.
Thanks I'll take a look at it.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Vector Fields에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by