help-octave
[Top][All Lists]
Advanced

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

Re: problems with arrayfun


From: Jordi Gutiérrez Hermoso
Subject: Re: problems with arrayfun
Date: Thu, 31 Jan 2013 10:52:58 -0500

On 30 January 2013 20:29, tobilo <address@hidden> wrote:
> I am using octave 3.0.5 on a linux cluster.

Ancient RHEL, right? If you want a newer rpm and you can't build it
yourself, we have some for sale. Contact us at address@hidden for a
quote.

> the following lines work fine in matlab, but fail in octave:
>
> iid = arrayfun(@subfunc1,(1:n)','UniformOutput',false);
>
> function iid = subfunc1(i)
>     j  = (i+1:n)';
>     d = sqrt(sum(bsxfun(@minus,X(i,:),X(j,:)).^2,2));
>     I  = d<=dmax;
>     iid = [j(I) d(I)];
> end

What are all those variables you are not defining in the function? X,
n, dmax? How is this code even running? Guessing at some arbitrary
values of them, I'm able to run the modified code in Octave 3.6.3
without error.

    1;

    function iid = subfunc1(i)
      n = 5;
      dmax = 10;
      X = rand(5);
      j  = (i+1:n)';
      d = sqrt(sum(bsxfun(@minus,X(i,:),X(j,:)).^2,2));
      I  = d<=dmax;
      iid = [j(I) d(I)];
    endfunction

    iid = arrayfun(@subfunc1,(1:n)','UniformOutput',false);

HTH,
- Jordi G. H.


reply via email to

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