
How can I plot a velocity field plot with color code?
조회 수: 9 (최근 30일)
이전 댓글 표시
Hello,
I want to plot the velocity field of my data with color code according to the vector magnitude.
I got my nx1 vectors for x,y,vx,vy which represent x position, y position, x direction velocity and y direction velocity. I am using
figure quiver(x,y,vx,vy);
My question is, should I be using some other function to plot the color coded velocity field or does the function 'quiver' have the feature of color code?
Thanks
댓글 수: 0
답변 (1개)
Gautam
2024년 10월 23일
Hello Emre
The “quiver” function in MATLAB does not natively support color coding based on vector magnitude. However, you can achieve this by plotting each vector individually and setting the color according to its magnitude
[x,y] = meshgrid(-pi:pi/8:pi,-pi:pi/8:pi);
vx = sin(y);
vy = cos(x);
magnitude = sqrt(vx.^2 + vy.^2);
magnitude_normalized = (magnitude - min(magnitude)) ./ (max(magnitude) - min(magnitude));
cmap = jet(256);
figure;
hold on;
for i = 1:length(x)
for j=1:length(y)
% Determine color index
color_idx = round(magnitude_normalized(i,j) * (length(cmap) - 1)) + 1;
% Plot vector with color
quiver(x(i,j), y(i,j), vx(i,j), vy(i,j),1, 'Color', cmap(color_idx, :));
end
end
hold off;
colorbar;
colormap(cmap);
This produces the following output

댓글 수: 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!