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

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 commentaires

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.
Thank you! So the straightforward answer to my question would be a NO!!

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Vector Fields dans Centre d'aide et File Exchange

Produits

Version

R2019a

Question posée :

le 2 Juil 2019

Commenté :

le 2 Juil 2019

Community Treasure Hunt

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

Start Hunting!

Translated by