"James Tursa" wrote in message <kmglkp$2ss$1@newscl01ah.mathworks.com>...
> "Elnaz " <ebsadeghian@gmail.com> wrote in message <kmgclt$451$1@newscl01ah.mathworks.com>...
> > Hi all,
> > I have a big 3D matix that I want to squueze into a 2D one while picking up the values that are bigger in absolute magnitute in the third dimension:
> > [c,in]=max(abs(s),[],3);
> > x = s(:,:,in);
> > s is the 3D matrix of size 5 X 20480 X 2. So I want to squeeze it along the 3rd dimension by comparing the values.
> > I get the "out of memory" error. I don't want to use loops. How can I address this problem?
>
> Your s(:,:,in) is not doing what you think it is doing ... it is trying to create a 5 x 20480 x (5*20480) result (hence the out of memory error). I think what you want is this instead:
>
> [c,in]=max(abs(s),[],3);
> z = size(s);
> n = z(1) * z(2);
> x = reshape(s((1:n)+(in(:)'1)*n,z(1:2));
I add one missing closing parenthesis in James's solution
x = reshape(s((1:n)+(in(:)'1)*n),z(1:2));
% Bruno
