Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Matrix manipulation/comparison

Subject: Matrix manipulation/comparison

From: Elnaz

Date: 9 May, 2013 14:43:09

Message: 1 of 4

Hi all,
I have a big 3-D matix that I want to squueze into a 2-D 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?

Thanks,
Elnaz

Subject: Matrix manipulation/comparison

From: James Tursa

Date: 9 May, 2013 17:16:09

Message: 2 of 4

"Elnaz " <ebsadeghian@gmail.com> wrote in message <kmgclt$451$1@newscl01ah.mathworks.com>...
> Hi all,
> I have a big 3-D matix that I want to squueze into a 2-D 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));

James Tursa

Subject: Matrix manipulation/comparison

From: Bruno Luong

Date: 9 May, 2013 17:32:06

Message: 3 of 4

"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 3-D matix that I want to squueze into a 2-D 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

Subject: Matrix manipulation/comparison

From: James Tursa

Date: 9 May, 2013 18:26:16

Message: 4 of 4

"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <kmgmim$5u7$1@newscl01ah.mathworks.com>...
> "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 3-D matix that I want to squueze into a 2-D 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

Thanks. (The dangers of posting on a computer without MATLAB installed ...)

James Tursa

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us