How can I delete the extra matrices which contain NaN and 0 values?

1 view (last 30 days)
Dear All, I have a 30 year dataset (1961.02.1-1990.11.30) in cell array which contains 358 matrices where the data are stored longitude x latitude x days. I had to convert this cell to 4D matrix for calculation. I carried out this by the following way:
maxSize = max(cellfun(@(x) size(x,3),out_m));
f = @(x) cat(3, x, nan(size(x,1),size(x,2),maxSize-size(x,3)));
out_m2 = cellfun(f,out_m,'UniformOutput',false);
PL = bsxfun(@times, out_m2, l);
PL2=reshape(num2cell(PL,[1 2 3]),[],1);
P_scen=cat(3,PL2{:});
Thust every month has 31 days. I would like to write the P_scen into netcdf file. The values are stored longitude x latitude x time. Its time length is 11098 due to the conversation. The time has to be determined in netcdf file by:
T(:,1)=[datenum(1961,2,1,0,0,0):datenum(1990,11,30)];
time(:,1)=T(:,1)-datenum(1950,1,1);
So this time length is 10895. How can I delete the extra days which contain NaN and 0 values? Thank you for your help in advance!
  2 Comments
Szabó-Takács Beáta
Szabó-Takács Beáta on 28 Apr 2015
Meantime came to my mind a solution. This is the following:
ARR = P_scen(:,:,:);
a = datenum([1961 2 1; 1990 11 30]);
yy=[1961 1 1; 1961 2 1; 1961 3 1;...; 1990 12 1];
[yyyy,mm,dd] = datevec((a(1):a(2))');
n=numel(dd);
ii = cumsum(ismember([yyyy,mm,dd],yy,'rows'));
pr = accumarray(ii,(1:n)',[],@(x){ARR(:,:,x)});
Pr = cat(3,pr{:});

Sign in to comment.

Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!