Clear Filters
Clear Filters

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

4 views (last 30 days)
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 Comments
dpb
dpb on 2 Jul 2019
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.

Sign in to comment.

Answers (0)

Categories

Find more on Vector Fields in Help Center and File Exchange

Products


Release

R2019a

Community Treasure Hunt

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

Start Hunting!