Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
Drexel University or The Math Forum.



Re: deleting rows from 3D arrays
Posted:
Aug 26, 2013 4:34 PM


On Tuesday, August 27, 2013 6:55:09 AM UTC+12, Nick wrote: > I have a data set consisting of multiple years of measurements of limnological variables, measured several time each month. Across years, measurements do not all occur on the same Julian Date,nor are the same total number of measurements taken each year. There are many zeros. As part of a jackknife (leaveoneout) regression analysis, I want to remove entire years, oneatatime, to calculate regression parameters on average daily values of the retained data. I have simulated 20 years of the kind of data I need to analyze and placed a year counter in the second column of the simulated multiyear data. This data set is 2D (rows and columns). I created a 3D array of 20 2_D arrays each consisting of a different combination of 19 years of data, using the following script: > > for i = 1:nyears > > Out(Out(:,2)~=i,:); > > A(1:length(Out(Out(:,2)~=i,:)),:,i) =Out(Out(:,2)~=i,:); > > end > > Each of the 20 2_D arrays contains the correct annual data, and all are the same length, which means each has a different number of terminal zeros in the last rows. I need to delete all such rows containing zeros. So not all final 2D array will have the same length. I can do this one 2D array at a time by replacing zeros with NaN's in each and then assigning a unique variable name to each and using > > X(any(isnan(X),2),:) = []; BUT I cannot succeed in using this command in a for loop to eliminate the zerorows in one fell swoop. It seems that Matlab should easily be able to do this. But I can't figure it out.
The way I do this is to retain the NaNs, but to ignore them when processing. Have a look at nanmean, for example, to see how to do this.



