Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

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


Math Forum » Discussions » Software » comp.soft-sys.matlab

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

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Derek Goring

Posts: 3,919
Registered: 12/7/04
Re: deleting rows from 3-D arrays
Posted: Aug 26, 2013 4:34 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

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.




Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.