Thread Subject: looping/vectorising issue...

Subject: looping/vectorising issue...

From: Rich

Date: 12 Feb, 2009 11:01:04

Message: 1 of 5

Anyone have any suggestions on how to vectorise this loop? (by vectorise, i guess i mean converting to matrix multiplication)

I'm at a loss!

dimensions are:
z1(m,n)
z2(m,k)
z3(m,n*k)

for i=1:size(z1,1)
    z3(i,:)=reshape(z1(i,:)'*z2(i,:),1,[]);
end



thanks heaps!

Subject: looping/vectorising issue...

From: Roger Stafford

Date: 12 Feb, 2009 16:57:01

Message: 2 of 5

"Rich " <richardwood@removethishotmail.com> wrote in message <gn0vhg$rn$1@fred.mathworks.com>...
> Anyone have any suggestions on how to vectorise this loop? (by vectorise, i guess i mean converting to matrix multiplication)
>
> I'm at a loss!
>
> dimensions are:
> z1(m,n)
> z2(m,k)
> z3(m,n*k)
>
> for i=1:size(z1,1)
> z3(i,:)=reshape(z1(i,:)'*z2(i,:),1,[]);
> end
>
> thanks heaps!

 [I,J] = ndgrid(1:n,1:k);
 z3 = z1(:,I).*z2(:,J);

Roger Stafford

Subject: looping/vectorising issue...

From: Rich

Date: 13 Feb, 2009 10:06:02

Message: 3 of 5

thanks Roger, you are a legend, and have saved me 75% of my runtime!

Subject: looping/vectorising issue...

From: Rich

Date: 18 Jun, 2009 11:40:20

Message: 4 of 5

So I hit memory problems as soon as I do this for big matrices (thousands by thousands), maybe I should have mentioned that before.
So, does anyone have a less memory intensive version?

I am generally working with sparse matrices, so I think I have to kick my brain into gear enough to work out how to use the find command in this context. But any pointers would be much appreciated!

thanks

Subject: looping/vectorising issue...

From: Rune Allnor

Date: 18 Jun, 2009 13:53:09

Message: 5 of 5

On 18 Jun, 13:40, "Rich " <richardw...@removethishotmail.com> wrote:
> So I hit memory problems as soon as I do this for big matrices (thousands by thousands), maybe I should have mentioned that before.
> So, does anyone have a less memory intensive version?

That's the problem with 'vectorization': You gain some speed at
the expense of memory.

If you're hitting the memory wall, you have two options:

1) Buy a bigger computer.
2) Implement a MEX routine in C or C++.

Rune

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

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.

Tag Activity for This Thread
Tag Applied By Date/Time
for loop Sprinceana 18 Jun, 2009 08:51:24
rssFeed for this Thread
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com