Guest User

Untitled

a guest
Jan 19th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. G = NaN(250,250);
  2. a = ceil(rand(1,50)*250*250);
  3. b = ceil(rand(1,50)*250*250);
  4. G (a) = 1; G (b) = 0;
  5.  
  6. % find the non-NaN entries in G
  7. idx = ~isnan(G);
  8.  
  9. % find their corresponding row/column indices
  10. [i,j] = find(idx);
  11.  
  12. % resize your matrix as desired, i.e. scale the row/column indices
  13. i = ceil(i*100/250);
  14. j = ceil(j*100/250);
  15.  
  16. % write the old non-NaN entries to Gnew using accumarray
  17. % you have to set the correct size of Gnew explicitly
  18. % maximum value is chosen if many entries share the same scaled i/j indices
  19. % NaNs are used as the fill
  20. Gnew = accumarray([i, j], G(idx), [100 100], @max, NaN);
Add Comment
Please, Sign In to add comment