How can I synchronize nan across dimensions of a matrix?
4 views (last 30 days)
How can I set all elements that are nan in one dimension also nan in another dimension?
My example: I have a 3d-matrix A of size(A)
ans = 34168 30 13
Let this any model output for e.g. 34168 grid points g in a map, 30 years y and 13 models m. Now I need to set all values of a given model m to nan, if the value from any other model m at that position is nan. In other words: I need to set A(g,y,1) nan if A(g,y,2) is nan, A(g,y,1) nan if A(g,y,3) is nan...and that for all g,y, and m.
Now I have a loop which should do the job, but it seems that 16 GB RAM are not enough, since it takes forever:
A=rand(34168,30,13); %just for illustration
A(b)=nan; %set random numbers to nan
%After synchronization the number of nan in each m should be the same, e.g. test through
I know, these are a lot of nan (>10 % of elements), but there should be a way to make this way faster.
Any help and hint is greatly appreciated.