help-octave
[Top][All Lists]

 From: Alvaro Aguilera Subject: Re: Easy about Matrices Date: Tue, 19 Apr 2005 09:59:55 +0200

Thanks for all the responses!!

In fact what I am doing is a simulation of a McCulloch-Pitts neuron, and for that I have a matrix X(n,2) with sample input, a matrix W(1,2) with an associated weight for X, then I plot x(:,1),x(:,2), but the "sign" of this result is given by  "y = w * x' -c" (with c constant).

I will try to use the tips you have given me, thanks.

On 4/19/05, Mike Miller <address@hidden> wrote:
On Tue, 19 Apr 2005, Geordie McBain wrote:

> I won't claim this is less awkward, but it does do the job without a
> loop:
>
>      octave> X = [1, 3, 9, 2, 4, 2, 7, 5, 3, 2, 9, 7]';
>      octave> Y = [2, 3, 9]';
>      octave> mod (find (kron (X, ones (1, length (Y))) == kron (Y', ones (length (X), 1))), length (X))
>      ans =
>
>         4
>         6
>        10
>         2
>         9
>         3
>        11
>
>      octave>
>
> which gives the same ans as your index, below.

Thank you, Geordie.  That is a step forward.  It would work nicely for
certain matrix sizes but it won't scale well if the X and Y vectors get
very long.  By the way, we noted some years ago on this list that
multiplication is faster than kron, when multiplication can be used, so I
think this might work faster than the above:

mod (find (X*ones(1,length(Y)) == ones(length(X),1)*Y'), length (X))

That was a nice tip, Geordie.  Thanks again.  Of course, if anyone else
has more ideas, I'm all ears!

Mike

>> I can see how to do it with a loop...
>>
>> index=find(X==Y(1)); for i=2:length(Y), index=[index ; find(X==Y(i))]; end
>>
>> ...but can it be done without a loop?  (Also, my method is a little
>> awkward and I wouldn't mind hearing about how I could do it better.)

-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:   http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:   http://www.octave.org/archive.html
-------------------------------------------------------------