Tips & Tricks
Follow


Fill array with NaNs

Bruno Luong on 28 Oct 2024 (Edited on 28 Oct 2024)
Latest activity Edit by Bruno Luong on 28 Oct 2024

Time to time I need to filll an existing array with NaNs using logical indexing. A trick I discover is using arithmetics rather than filling. It is quite faster in some circumtances
A=rand(10000);
b=A>0.5;
tic; A(b) = NaN; toc
Elapsed time is 0.737291 seconds.
tic; A = A + 0./~b; toc;
Elapsed time is 0.027666 seconds.
If you know trick for other value filling feel free to post.
goc3
goc3 on 28 Oct 2024
That is a clever trick.
Chen Lin
Chen Lin on 28 Oct 2024
Thanks for sharing this quick trick, Bruno. This marks your first post and we look forward to seeing more.

Tags

No tags entered yet.