Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: deleting rows from 3-D arrays
Replies: 2   Last Post: Aug 26, 2013 4:34 PM

 Messages: [ Previous | Next ]
 Nick Posts: 7 Registered: 11/2/09
deleting rows from 3-D arrays
Posted: Aug 26, 2013 2:55 PM

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.

Date Subject Author
8/26/13 Nick
8/26/13 dpb
8/26/13 Derek Goring