help-octave
[Top][All Lists]
Advanced

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

Re: Apply Polyval to Array


From: Thomas D. Dean
Subject: Re: Apply Polyval to Array
Date: Sun, 12 Jun 2016 20:58:36 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.8.0

On 06/12/2016 08:42 PM, Dmitri A. Sergatskov wrote:
On Sun, Jun 12, 2016 at 10:25 PM, Doug Stewart <address@hidden
<mailto:address@hidden>> wrote:



    On Sun, Jun 12, 2016 at 10:03 PM, Thomas D. Dean
    <address@hidden <mailto:address@hidden>> wrote:

        I want to vectorize this:

        p1 = [1,2,3;4,5,6;7,8,9];
        for idx=1:3
           polyval(p1(idx,:),0)
        endfor

        cellfun("polyval",{p1},{[0;0;0]}); ## fails
        arrayfun("polyval",p1,0 "UniformOutput",false)); ## wrong
        arrayfun("polyval",p1,zeros(3,3), "UniformOutput",false); ## wrong

        Tom Dean

        _______________________________________________
        Help-octave mailing list
        address@hidden <mailto:address@hidden>
        https://lists.gnu.org/mailman/listinfo/help-octave


    does this help

    p1 = [1,2,3;4,5,6;7,8,9];
    t=[1 2 3]
    f=@(t) polyval(p1(t,:),0)
    arrayfun(f,t)



​it works, but hardly faster than the loop on my computer.

​>> p1=rand(1000);
 >> tic; for idx=1:1000; polyval(p1(idx,:),0) ; endfor; toc
Elapsed time is 4.96287 seconds.
 >> t=1:1000;
 >> f=@(t) polyval(p1(t,:),0)
f =

@(t) polyval (p1 (t, :), 0)

 >> tic; arrayfun(f,t); toc
Elapsed time is 4.82834 seconds.

​Dmitri.
--

To get faster, the interpreter can not be involved in a loop, as in the case of the function t.

Tom Dean




reply via email to

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