Hi i have data of wind direction , speed, and temperature.
wdir = [45 90 90];
knots = [6 6 8 ];
temp=[10 5 -2];
Using the following lines i can get the compass plot for wind direction and speed.
rdir = wdir * pi/180;
[x,y] = pol2cart(rdir,knots);
compass(x,y);
But is there any way to color code the arrows using the temp values, and give the legend of the temp color code. Seeking help from matlab experts, Thanks in advance.

 채택된 답변

Kelly Kearney
Kelly Kearney 2014년 2월 14일

1 개 추천

Compass produces individual line object, not tied to a colormap, so you'll have to do the color-matching yourself:
wdir = [45 90 90];
knots = [6 6 8 ];
temp= [10 5 -2];
rdir = wdir * pi/180;
[x,y] = pol2cart(rdir,knots);
h = compass(x,y);
tcol = interpcolor(temp, jet(64), [-5 10]);
set(h, {'color'}, num2cell(tcol,2));
colormap(jet);
set(gca, 'clim', [-5 10]);
colorbar;
Find interpcolor here. Note that the colormap and colorbar in the above figure are for reference only; they don't actually link to the colors of the arrows.
(Also, you really shouldn't accept an answer if it doesn't actually answer your question).

댓글 수: 5

mavelli
mavelli 2014년 2월 19일
Hi Kelly, your solution is what I was looking for. But I want to link the color of the rows ie, the arrow created using each set of wdir,knots to the corresponding temp value.
Thanks in advance
mavelli
mavelli 2014년 3월 3일
Or is it anyway possible to get the actual rgb matrix values of each colormap and individually assign it to the wind arrows.
Kelly Kearney
Kelly Kearney 2014년 3월 11일
My solution does exactly that... figures out the rgb values associated with each temp value, then uses that to color each corresponding arrow. If my example doesn't produce the intended result, can you clarify exactly what is unexpected?
mavelli
mavelli 2014년 3월 29일
hI KELLY the solution worked perfectly for me. Thank a lot.Can you fix the concentric circles inside the compass plots ie the wind speed can be limited and also the thickeness of the arrows. I tried the Linespecs but it did not work.
h = compass(x,y,'LineWidth',3);
Unlike most plotting functions, the compass function doesn't accept parameter/value pairs as an input, only a single Linespec to set color and linestyle. So you have to do that after the fact:
h = compass(x,y);
set(h, 'linewidth', 3);
Not sure what you mean by "fix the concentric circles"...

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Azzi Abdelmalek
Azzi Abdelmalek 2014년 2월 14일

1 개 추천

wdir = [45 90 90];
knots = [6 6 8 ];
temp=[10 5 -2];
rdir = wdir * pi/180;
[x,y] = pol2cart(rdir,knots);
h=compass(x,y);
set(h(1),'color','r')
set(h(2),'color','b')
set(h(3),'color','g')
legend({'h1' 'h2' 'h3'})

카테고리

도움말 센터File Exchange에서 Vector Fields에 대해 자세히 알아보기

태그

질문:

2014년 2월 14일

댓글:

2014년 3월 31일

Community Treasure Hunt

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

Start Hunting!

Translated by