Is it possible to plot vectors in different colors using a single quiver statement?

4 次查看(过去 30 天)
Suppose I have the following code:
coltab = ([128,0,0; 0,255,0; 0,0,255; 255,255,0; 255,116,140])/255;
% I have the above colors predefined
x = [1:5];
y = [10:15];
u = [1 2 3 -4 -5];
v = [1 -1 -2 -3 2 ];
color_index = [1; 2; 2; 3; 4] %can be any value since it is computed seperately
I need to plot these vectors and its color must be based on the variable "color_index". One way to day is:
hold on;
for i=1:length(x)
quiver(x(i),y(i),u(i),v(i),'color', coltab(color_index(i,1),:));
end
hold off;
Here, based on the length of the data the "quiver" function is repeteadly called which is a slow process.
Is there any way to vectorize the for loop section and replace it with a single quiver statement ?
  2 个评论
dpb
dpb 2019-7-2
The quiver object is single handle for the entire object; there is no array to hold the 'Marker[Face|Edge]Color' properties separately by element so doesn't help even if were way to write without the loop.
You might search FEX to see if are any enhanced versions that do have the extra granularity already implemented.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Vector Fields 的更多信息

产品


版本

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by