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:
Resampling a matrix

Subject: Resampling a matrix

From: J s

Date: 4 Apr, 2011 17:11:05

Message: 1 of 4

I have two 3D matrices, A & B. I want to define a new cell matrix C the size of matrix A. For every point x in A I want the corresponding cell x in C to contain an (n x n x n) matrix from B centered on B(x). How do I do this without using a loop? A and B are large, so looping through each element in A is very slow.

Thanks.

Subject: Resampling a matrix

From: Sean de

Date: 4 Apr, 2011 17:48:04

Message: 2 of 4

"J s" <ohrtzi@hotmail.com.remove> wrote in message <incu39$4m7$1@fred.mathworks.com>...
> I have two 3D matrices, A & B. I want to define a new cell matrix C the size of matrix A. For every point x in A I want the corresponding cell x in C to contain an (n x n x n) matrix from B centered on B(x). How do I do this without using a loop? A and B are large, so looping through each element in A is very slow.
>
> Thanks.

You could kron B with ones(n,n,n) and then call mat2cell directly on B and extract according to A. I don't think this will be much faster than a well-written for-loop though.

Subject: Resampling a matrix

From: Sean de

Date: 4 Apr, 2011 17:57:05

Message: 3 of 4

"Sean de " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message
> You could kron B with ones(n,n,n) and then call mat2cell directly on B and extract according to A. I don't think this will be much faster than a well-written for-loop though.

Don't do this; my fingers out-typed my brain.

Subject: Resampling a matrix

From: J s

Date: 4 Apr, 2011 18:05:24

Message: 4 of 4

"Sean de " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message <ind08k$c7n$1@fred.mathworks.com>...
> "J s" <ohrtzi@hotmail.com.remove> wrote in message <incu39$4m7$1@fred.mathworks.com>...
> > I have two 3D matrices, A & B. I want to define a new cell matrix C the size of matrix A. For every point x in A I want the corresponding cell x in C to contain an (n x n x n) matrix from B centered on B(x). How do I do this without using a loop? A and B are large, so looping through each element in A is very slow.
> >
> > Thanks.
>
> You could kron B with ones(n,n,n) and then call mat2cell directly on B and extract according to A. I don't think this will be much faster than a well-written for-loop though.

Apparently, kron only works with 2D matrices. Good idea though, any others

Tags for 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