quiver plot - need help to remove NaN
8 次查看(过去 30 天)
显示 更早的评论
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 个评论
Giorgos Papakonstantinou
2014-11-18
编辑:Giorgos Papakonstantinou
2014-11-19
The Code button formats the code part in your answer. It is very easy to use this tool. You just highlight the code and you press the button. It improves the readability for someone who reads your question.
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
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
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 个)
另请参阅
类别
在 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!