
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!