"Thomas" wrote in message <k56mih$rv3$1@newscl01ah.mathworks.com>...
> I know how to accomplish this with a 2D matrix, but I am having trouble with the syntax to apply to a 3D matrix
>
> 2D 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 criterionmeeting number is in (:,:,1) or (:,:,2).
> The logic from the 2D 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 twodimensional array. I haven't tried this out.
Roger Stafford
