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 (leave-one-out) regression analysis, I want to remove entire years, one-at-a-time, 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 multi-year data. This data set is 2-D (rows and columns). I created a 3-D 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 2-D array will have the same length. I can do this one 2-D 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 zero-rows 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.