Scheduled service maintenance on November 22


On Friday, November 22, 2024, between 06:00 CET and 18:00 CET, GIN services will undergo planned maintenance. Extended service interruptions should be expected. We will try to keep downtimes to a minimum, but recommend that users avoid critical tasks, large data uploads, or DOI requests during this time.

We apologize for any inconvenience.

maskraster.m 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. function [maskM,x]=maskraster(x,y,pre,post,varargin)
  2. % [y,x]=maskraster(x,y,pre,post,[null_value])
  3. %
  4. %opts.null_value=nan;
  5. iod = @utils.inputordefault;
  6. null_value = iod('null_value',nan,varargin);
  7. %parseargs(varargin,opts,{},1);
  8. % x is a row vector of length s
  9. % y is a matrix with s columns and t rows
  10. % pre is a vector of length t (or scalar)
  11. % post is a vector of length t (or scalar)
  12. %
  13. % The function turns any elements of y that are before pre or after post
  14. % into NaNs. If pre or post falls into the middle of a bin that bin is set
  15. % to NaN
  16. %% Check that everything is the right length
  17. maskM=[];
  18. if numel(x) ~= size(y,2)
  19. fprintf(1,'numel(x) must equal size(y,2)');
  20. return;
  21. end
  22. if isscalar(pre)
  23. pre=zeros(1,size(y,1))+pre;
  24. elseif numel(pre)~=size(y,1)
  25. fprintf(1,'numel(pre) must equal size(y,2) or be scalar');
  26. return;
  27. end
  28. if isscalar(post)
  29. post=zeros(1,size(y,1))+post;
  30. elseif numel(post)~=size(y,1)
  31. fprintf(1,'numel(post) must equal size(y,2) or be scalar');
  32. return;
  33. end
  34. %% now loop through the trials
  35. maxx=numel(x);
  36. prex= stats.qfind(x,pre);
  37. postx= stats.qfind(x,post);
  38. maskM=y;
  39. for tx=1:numel(prex)
  40. if ismember(prex(tx),x)
  41. prex(tx)=prex(tx)-1;
  42. end
  43. % if prex is in the range of x
  44. if prex(tx)>0 && prex(tx)<=maxx;
  45. maskM(tx,1:prex(tx))=null_value;
  46. elseif isinf(pre(tx)) && pre(tx)>0
  47. maskM(tx,:)=null_value;
  48. end
  49. if postx(tx)>0 && post(tx)<=x(end)
  50. maskM(tx,postx(tx):end)=null_value;
  51. elseif isinf(post(tx)) && post(tx)<0
  52. maskM(tx,:)=null_value;
  53. end
  54. end