help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Vectorizing a summation


From: Michael Goffioul
Subject: Re: Vectorizing a summation
Date: Tue, 29 Jan 2013 09:21:02 -0500

On Tue, Jan 29, 2013 at 8:53 AM, rdelgado <address@hidden> wrote:
Hello,

I have a question about vectorizing a summation on Octave.

Suposse that I want to do this summation:

result = SUM(from i=1...MxN) SUM (from j=1...MxN) (Xi - Yi) * (Xj - Yj)

Where X, Y are MxN matrices.

Is there any way of doing that operation without for loops in Octave?
I can't find a way, but I am a beginner in Octave too.

Not 100% sure, but maybe the following:

z = X - Y;
z = z(:);
z = kron(z, z);
z = sum(z);

Michael.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]