quiver plot - need help to remove NaN

조회 수: 10(최근 30일)
Raydo Eugov
Raydo Eugov 2014년 11월 14일
편집: Giorgos Papakonstantinou 2014년 11월 19일
Hi all,
Thanks for your time reading this. I have some trouble to remove NaN values from my quiver plot. I've tried to replace them with zero but it didn't work too.
U(isnan(U))= 0;
Also, I've tried with index and replace it in quiver plot, with this I managed to remove the NaN values but I ended up plotted massive vectors which I don't know how to make them less dense without losing their original information.
idx = ~isnan(U) & ~isnan(V);
quiver(Xp(idx),Yp(idx),U(idx)),V(idx))
I'm not very sure what is a better way to plot them but I prefer not to scale my vector arrows to keep the original information. My script and a screenshot of my plot as follow where you can see black dotes on the land areas (Ireland, the UK and Europe) - this is a result from my SWAN wave model (0.05degree resolution). I want to remove those black dotes. Hope someone can help me. All my variables are in matrix (i.e 461x401) as attached. Sorry, I'm a new Matlab user. Thanks in advance!
figure
contourf(Xp,Yp,Hs,'LineColor','none');
caxis([0,10]);
colormap (jet);
colorbar
hold on;
quiver(Xp(1:15:end,1:15:end),Yp(1:15:end,1:15:end),U(1:15:end,1:15:end)),V(1:15:end,1:15:end)),...
'LineWidth',1,'Color','k') % plot for bigger size and less dense arrows
Thanks, Raydo
  댓글 수: 4
Andrew Reibold
Andrew Reibold 2014년 11월 18일
The code you provided produce a different plot for me with the attached data
I solved your issue for the plot below, see in the answers section. Let me know if your problem is resolved.

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

채택된 답변

Andrew Reibold
Andrew Reibold 2014년 11월 18일
편집: Andrew Reibold 2014년 11월 18일
This solution removes the black dots!
The reason it looked awful after removing NaNs is because instead of just taking the non-NaN indices of every 15th point, you took the non-Nan from EVERYTHING which was a TON more data points. even if the arrows were tiny, they still blotted out everything! I first made new variables including only what you wanted plotted, then removed the NaNs from there.
I commented out the quiver line in your original code and added new code below. Your data must be loaded first in the same format as presented in your attachment.
Best wishes! -Andrew
figure
contourf(Xp,Yp,Hs,'LineColor','none');
caxis([0,10]); colormap (jet);
colorbar
hold on;
% quiver(Xp(1:15:end,1:15:end),Yp(1:15:end,1:15:end),...
% U(1:15:end,1:15:end),V(1:15:end,1:15:end),...
% 'LineWidth',1,'Color','k') % plot for bigger size and less dense arrows
Xp2 = Xp(1:15:end,1:15:end);
Yp2 = Yp(1:15:end,1:15:end);
U2 = U(1:15:end,1:15:end);
V2 = V(1:15:end,1:15:end);
idx = ~isnan(U2) & ~isnan(V2);
quiver(Xp2(idx),Yp2(idx),U2(idx),V2(idx),'LineWidth',1,'Color','k')
  댓글 수: 2
Andrew Reibold
Andrew Reibold 2014년 11월 18일
No problem. Also, Giorgos mentioned in a comment on the question that "the Code button formats the code part in your answer. It is very is to use this tool. You just highlight the code and you press the button. It improves the readability for someone who reads your question."
I very much agree with his statement. Try to use the code button! :)
(Example is in the solution I posted, its just nicer for us to read, and its clear which parts are the code!)

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

추가 답변(0개)

태그

Community Treasure Hunt

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

Start Hunting!

Translated by