Clear Filters
Clear Filters

remove inf in quiver

2 views (last 30 days)
feynman feynman
feynman feynman on 28 Apr 2024
Commented: Star Strider on 29 Apr 2024
I want quiver(X,Y,u,v), but there's inf entries in u and v at positions x=y. I'm looking for the smartest way to skip these positions with inf u and v and finish the quiver.
x=-5:0.1:5;
y=-5:0.1:5;
[X,Y]=meshgrid(x,y);
  1 Comment
Dyuman Joshi
Dyuman Joshi on 28 Apr 2024
u and v aren't defined in the code.

Sign in to comment.

Accepted Answer

Star Strider
Star Strider on 28 Apr 2024
Without having ‘u’ and ‘v’ to work with, perhaps something like this using fillmissing (or fillmissing2) —
x=-5:0.1:5;
y=-5:0.1:5;
[X,Y]=meshgrid(x,y);
u = randn(size(X)); % Create 'u'
ix = sub2ind(size(u), 1:size(u,1), 1:size(u,2)); % Linear Inmdex To Create 'u' With Diagnonal 'Inf'
u(ix) = Inf
u = 101x101
Inf -1.4193 1.0497 -0.1100 0.2181 -2.3272 -0.1111 0.6233 -0.4594 0.1195 0.9566 -1.9244 -1.4146 -0.4970 0.0888 1.9743 0.4177 -0.6746 1.0932 1.6275 -0.3020 2.6394 0.0664 -0.9736 0.5496 0.9406 0.7607 -1.1810 0.1057 0.3238 -0.2040 Inf 1.4676 -0.4032 -0.8914 0.6347 0.2933 -0.7958 -0.5473 0.3441 -1.0796 -0.2790 -0.8720 -0.1744 1.0271 0.2945 -0.6075 -0.3061 0.9589 -0.3907 -0.1497 -0.5693 1.9353 -0.9865 1.5239 0.9541 1.2692 0.5700 0.6326 -0.2809 0.4440 0.1059 Inf -0.7628 -1.9011 0.4484 -0.6286 -0.0539 -0.9827 -0.1590 -1.1202 0.9885 -0.1086 -0.2550 0.5774 -0.3649 0.9951 0.3727 0.7720 0.5775 1.4696 -0.2848 0.2413 -0.7008 -1.0953 -1.5702 -0.5243 -0.0585 -2.2009 -2.7097 -1.1253 -0.7258 -0.8600 Inf -0.7818 0.0430 1.3831 0.4638 -1.8246 -0.5975 1.1344 -2.0120 0.3844 -1.4048 -0.7412 -0.7979 -0.3750 1.3553 -0.5779 0.0419 0.5819 1.2048 -0.7356 -0.4025 -0.4867 -2.7108 -0.5462 -0.5905 0.7864 -1.9629 0.7305 1.5534 0.0548 0.6495 Inf 0.9854 0.1087 0.1832 0.1335 2.4604 -0.5619 2.5730 0.3904 1.0272 -0.4547 1.0581 0.3803 0.3861 -0.6168 1.0308 -1.0501 1.1463 -0.4087 -0.2244 -1.0732 1.3175 -0.1320 0.2752 0.8637 -0.0700 1.5087 0.2137 -0.5525 0.6823 1.3532 Inf -0.9245 0.0744 -0.7550 -1.0429 -0.4523 0.1324 0.3328 0.8958 -0.8247 0.0939 -0.9691 -0.3163 0.4888 -0.2547 2.0617 -1.2665 -1.3080 -0.2838 0.4716 0.0971 1.3410 0.4530 -0.5502 -0.3113 -0.7899 -1.3514 1.8762 1.4511 -0.6696 0.6343 Inf 0.5961 0.5598 1.2437 0.3595 -0.3161 0.0932 1.3476 -1.0957 0.1353 0.3317 -1.3635 0.9710 1.6089 -1.9098 0.8884 0.3416 0.1062 0.8726 1.1483 -0.3553 -0.5328 -0.2019 -0.8153 0.7720 0.5451 0.7223 -1.8662 -0.6066 -0.0011 1.0699 Inf -0.3192 1.2113 -0.9188 -0.0333 -0.5733 0.0934 -0.1295 1.4446 -1.1444 1.1519 -0.9562 -0.6240 -0.0261 0.5102 -1.5159 -0.8370 0.7812 1.1397 0.1271 0.5030 -0.8183 1.9334 -1.0089 -1.5652 0.4866 -1.7667 0.1231 0.1948 -1.0970 -0.6456 Inf 0.6980 -1.0084 0.9558 -1.3121 -0.8189 -1.0246 -0.6636 -1.7755 0.1567 0.6217 -0.1159 0.8454 -0.0712 1.8066 -0.7937 0.6682 -0.0229 -1.0841 1.5203 -1.2465 -1.5232 0.1843 1.4161 1.2349 -1.0478 -0.4456 0.2213 0.2403 -0.9400 0.1554 Inf -0.4139 -1.0749 -0.7384 -1.5659 1.6817 -1.2396 -0.7250 0.3642 -0.1862 0.4102 1.0891 -0.9765 0.1297 1.0545 -0.4711 -0.9109 -1.2133 0.7924 -0.2372 -0.9673
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
u(isinf(u)) = NaN % Change 'Inf' To 'NaN'
u = 101x101
NaN -1.4193 1.0497 -0.1100 0.2181 -2.3272 -0.1111 0.6233 -0.4594 0.1195 0.9566 -1.9244 -1.4146 -0.4970 0.0888 1.9743 0.4177 -0.6746 1.0932 1.6275 -0.3020 2.6394 0.0664 -0.9736 0.5496 0.9406 0.7607 -1.1810 0.1057 0.3238 -0.2040 NaN 1.4676 -0.4032 -0.8914 0.6347 0.2933 -0.7958 -0.5473 0.3441 -1.0796 -0.2790 -0.8720 -0.1744 1.0271 0.2945 -0.6075 -0.3061 0.9589 -0.3907 -0.1497 -0.5693 1.9353 -0.9865 1.5239 0.9541 1.2692 0.5700 0.6326 -0.2809 0.4440 0.1059 NaN -0.7628 -1.9011 0.4484 -0.6286 -0.0539 -0.9827 -0.1590 -1.1202 0.9885 -0.1086 -0.2550 0.5774 -0.3649 0.9951 0.3727 0.7720 0.5775 1.4696 -0.2848 0.2413 -0.7008 -1.0953 -1.5702 -0.5243 -0.0585 -2.2009 -2.7097 -1.1253 -0.7258 -0.8600 NaN -0.7818 0.0430 1.3831 0.4638 -1.8246 -0.5975 1.1344 -2.0120 0.3844 -1.4048 -0.7412 -0.7979 -0.3750 1.3553 -0.5779 0.0419 0.5819 1.2048 -0.7356 -0.4025 -0.4867 -2.7108 -0.5462 -0.5905 0.7864 -1.9629 0.7305 1.5534 0.0548 0.6495 NaN 0.9854 0.1087 0.1832 0.1335 2.4604 -0.5619 2.5730 0.3904 1.0272 -0.4547 1.0581 0.3803 0.3861 -0.6168 1.0308 -1.0501 1.1463 -0.4087 -0.2244 -1.0732 1.3175 -0.1320 0.2752 0.8637 -0.0700 1.5087 0.2137 -0.5525 0.6823 1.3532 NaN -0.9245 0.0744 -0.7550 -1.0429 -0.4523 0.1324 0.3328 0.8958 -0.8247 0.0939 -0.9691 -0.3163 0.4888 -0.2547 2.0617 -1.2665 -1.3080 -0.2838 0.4716 0.0971 1.3410 0.4530 -0.5502 -0.3113 -0.7899 -1.3514 1.8762 1.4511 -0.6696 0.6343 NaN 0.5961 0.5598 1.2437 0.3595 -0.3161 0.0932 1.3476 -1.0957 0.1353 0.3317 -1.3635 0.9710 1.6089 -1.9098 0.8884 0.3416 0.1062 0.8726 1.1483 -0.3553 -0.5328 -0.2019 -0.8153 0.7720 0.5451 0.7223 -1.8662 -0.6066 -0.0011 1.0699 NaN -0.3192 1.2113 -0.9188 -0.0333 -0.5733 0.0934 -0.1295 1.4446 -1.1444 1.1519 -0.9562 -0.6240 -0.0261 0.5102 -1.5159 -0.8370 0.7812 1.1397 0.1271 0.5030 -0.8183 1.9334 -1.0089 -1.5652 0.4866 -1.7667 0.1231 0.1948 -1.0970 -0.6456 NaN 0.6980 -1.0084 0.9558 -1.3121 -0.8189 -1.0246 -0.6636 -1.7755 0.1567 0.6217 -0.1159 0.8454 -0.0712 1.8066 -0.7937 0.6682 -0.0229 -1.0841 1.5203 -1.2465 -1.5232 0.1843 1.4161 1.2349 -1.0478 -0.4456 0.2213 0.2403 -0.9400 0.1554 NaN -0.4139 -1.0749 -0.7384 -1.5659 1.6817 -1.2396 -0.7250 0.3642 -0.1862 0.4102 1.0891 -0.9765 0.1297 1.0545 -0.4711 -0.9109 -1.2133 0.7924 -0.2372 -0.9673
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
u = fillmissing(u,'linear') % Use 'fillmissing'
u = 101x101
-0.8520 -1.4193 1.0497 -0.1100 0.2181 -2.3272 -0.1111 0.6233 -0.4594 0.1195 0.9566 -1.9244 -1.4146 -0.4970 0.0888 1.9743 0.4177 -0.6746 1.0932 1.6275 -0.3020 2.6394 0.0664 -0.9736 0.5496 0.9406 0.7607 -1.1810 0.1057 0.3238 -0.2040 -0.6567 1.4676 -0.4032 -0.8914 0.6347 0.2933 -0.7958 -0.5473 0.3441 -1.0796 -0.2790 -0.8720 -0.1744 1.0271 0.2945 -0.6075 -0.3061 0.9589 -0.3907 -0.1497 -0.5693 1.9353 -0.9865 1.5239 0.9541 1.2692 0.5700 0.6326 -0.2809 0.4440 0.1059 0.3038 -0.7628 -1.9011 0.4484 -0.6286 -0.0539 -0.9827 -0.1590 -1.1202 0.9885 -0.1086 -0.2550 0.5774 -0.3649 0.9951 0.3727 0.7720 0.5775 1.4696 -0.2848 0.2413 -0.7008 -1.0953 -1.5702 -0.5243 -0.0585 -2.2009 -2.7097 -1.1253 -0.7258 -0.8600 -0.0567 -0.7818 0.0430 1.3831 0.4638 -1.8246 -0.5975 1.1344 -2.0120 0.3844 -1.4048 -0.7412 -0.7979 -0.3750 1.3553 -0.5779 0.0419 0.5819 1.2048 -0.7356 -0.4025 -0.4867 -2.7108 -0.5462 -0.5905 0.7864 -1.9629 0.7305 1.5534 0.0548 0.6495 0.2857 0.9854 0.1087 0.1832 0.1335 2.4604 -0.5619 2.5730 0.3904 1.0272 -0.4547 1.0581 0.3803 0.3861 -0.6168 1.0308 -1.0501 1.1463 -0.4087 -0.2244 -1.0732 1.3175 -0.1320 0.2752 0.8637 -0.0700 1.5087 0.2137 -0.5525 0.6823 1.3532 0.8098 -0.9245 0.0744 -0.7550 -1.0429 -0.4523 0.1324 0.3328 0.8958 -0.8247 0.0939 -0.9691 -0.3163 0.4888 -0.2547 2.0617 -1.2665 -1.3080 -0.2838 0.4716 0.0971 1.3410 0.4530 -0.5502 -0.3113 -0.7899 -1.3514 1.8762 1.4511 -0.6696 0.6343 0.0727 0.5961 0.5598 1.2437 0.3595 -0.3161 0.0932 1.3476 -1.0957 0.1353 0.3317 -1.3635 0.9710 1.6089 -1.9098 0.8884 0.3416 0.1062 0.8726 1.1483 -0.3553 -0.5328 -0.2019 -0.8153 0.7720 0.5451 0.7223 -1.8662 -0.6066 -0.0011 1.0699 -0.0247 -0.3192 1.2113 -0.9188 -0.0333 -0.5733 0.0934 -0.1295 1.4446 -1.1444 1.1519 -0.9562 -0.6240 -0.0261 0.5102 -1.5159 -0.8370 0.7812 1.1397 0.1271 0.5030 -0.8183 1.9334 -1.0089 -1.5652 0.4866 -1.7667 0.1231 0.1948 -1.0970 -0.6456 -0.0819 0.6980 -1.0084 0.9558 -1.3121 -0.8189 -1.0246 -0.6636 -1.7755 0.1567 0.6217 -0.1159 0.8454 -0.0712 1.8066 -0.7937 0.6682 -0.0229 -1.0841 1.5203 -1.2465 -1.5232 0.1843 1.4161 1.2349 -1.0478 -0.4456 0.2213 0.2403 -0.9400 0.1554 0.8220 -0.4139 -1.0749 -0.7384 -1.5659 1.6817 -1.2396 -0.7250 0.3642 -0.1862 0.4102 1.0891 -0.9765 0.1297 1.0545 -0.4711 -0.9109 -1.2133 0.7924 -0.2372 -0.9673
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
Use whatever interpolation method you want with fillmissing. There are several options.
.
  4 Comments
feynman feynman
feynman feynman on 29 Apr 2024
Thank you so much!
Star Strider
Star Strider on 29 Apr 2024
As always, my pleasure!

Sign in to comment.

More Answers (0)

Categories

Find more on Vector Fields in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!