quiver plot - need help to remove NaN
Show older comments
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 Comments
Andrew Reibold
on 14 Nov 2014
Removing the black dots in the white areas is all you want to do?
Raydo Eugov
on 18 Nov 2014
Giorgos Papakonstantinou
on 18 Nov 2014
Edited: Giorgos Papakonstantinou
on 19 Nov 2014
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
on 18 Nov 2014
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.
Accepted Answer
More Answers (0)
Categories
Find more on Vector Fields in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!