How to add colourmap to 2D vectorplot created by using quiver
조회 수: 9 (최근 30일)
이전 댓글 표시
Hello all,
I have created 2D vector plot by using quiver i.e( quiver (x,y,u,v)), i am getting vecrot plot of 20*9 ( totally 180 vectors) . i have to add colours to this vector plot where colour of the plot represents the magnitude of vector at that index along with vectors in the plot with colour bar the end. kindly help me in this and any proper sources for learning the matlab as i am a beginner.
Thank in advance
댓글 수: 0
답변 (2개)
Shubham Rawat
2021년 1월 25일
Hi HariKrishna,
You may use this file to solve your problem:
You can download this file and run into your MATLAB. This contains a function quiverwcolorbar, which can colour the vector plot according to their vector magnitude.
Hope this helps!
댓글 수: 1
darova
2021년 2월 4일
Try this example
clc,clear
[x,y,z] = peaks(20); % generate data
[u,v] = gradient(z,1); % create u and v vectors
h = quiver(x,y,u,v); % display standard quiver
% extract each arrow separately
c = get(h,'children');
x1 = get(c(2),'xdata'); % arrow body
y1 = get(c(2),'ydata');
x2 = get(c(3),'xdata'); % arrow head
y2 = get(c(3),'ydata');
cmap = jet(200); % generate 200 colors
% color arrows according to Z values
F = scatteredInterpolant(x,y,z);
zmin = min(z(:));
k = max(z(:)) - min(z(:));
for i = 1:3:length(x1);
ii = (F(x1(i),y1(i))-zmin)/k*199; % scale Z value (0-199)
ii = round(ii)+1; % index of color
line(x1(i:i+2),y1(i:i+2),'color',cmap(ii)) % body
line(x2(i:i+2),y2(i:i+2),'color',cmap(ii)) % head
end
참고 항목
카테고리
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!