Is it possible to plot vectors in different colors using a single quiver statement?
조회 수: 5 (최근 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
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 Center 및 File Exchange에서 Vector Fields에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!