```Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: conditional column delete (3D matrix)
Date: Thu, 11 Oct 2012 16:56:07 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 29
Message-ID: <k56tn7\$qf1\$1@newscl01ah.mathworks.com>
References: <k56mih\$rv3\$1@newscl01ah.mathworks.com>
NNTP-Posting-Host: www-00-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: newscl01ah.mathworks.com 1349974567 27105 172.30.248.45 (11 Oct 2012 16:56:07 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 11 Oct 2012 16:56:07 +0000 (UTC)
Xref: news.mathworks.com comp.soft-sys.matlab:780458

"Thomas" wrote in message <k56mih\$rv3\$1@newscl01ah.mathworks.com>...
> I know how to accomplish this with a 2-D matrix, but I am having trouble with the syntax to apply to a 3-D matrix
>
> 2-D example: Let's say A is a 10x5 matrix.
> If any column of A meets a criterion, I want to delete the whole column. If my criterion is any element greater than 10, I can do this:
> A = rand(10,5)*10; A(3,2) = 11; A(5,4) = 12; % create matrix
> A(:,max(A)>10) = []; % delete the two columns containing number > 10
> I'm left with a 10x3 matrix comprising the original columns 1, 3 and 5.
>
> But, what if it's a 10x5x2 matrix. Same criterion, but now, when criterion is met, I want to delete columns across both levels of the 3rd dimension. (That is, my goal is a 10x3x2).
> Note, the criterion would apply to either level of the 3rd dimension. So...
> B = rand(10,5,2)*10; B(3,2,1) = 11; B(5,4,2) = 12;
> Columns 2 and 4 meet the criterion regardless of whether the location of the criterion-meeting number is in (:,:,1) or (:,:,2).
> The logic from the 2-D examples above led me to think that something like this should work:
> B(:,max(B)>10,:) = [];
> But no joy. I get 'Matrix index is out of range for deletion.' I've tried several other variants and I can't quite get it. Suggestions? Thanks,
> -Tom
- - - - - - - - - - - -
How about using the 'any' function?

B(:,any(any(B>10,2),3),:) = [];

Or perhaps it should be:

B(:,any(any(B>10,2),2),:) = [];

if the inner 'any' result collapses to a true two-dimensional array.  I haven't tried this out.

Roger Stafford
```