help-octave
[Top][All Lists]
Advanced

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

Re: [newbie] how to avoid a for-loop


From: Marco Atzeri
Subject: Re: [newbie] how to avoid a for-loop
Date: Thu, 18 Dec 2014 18:26:37 +0100
User-agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.3.0

On 12/18/2014 5:40 PM, Jean Dubois wrote:
Can anyone here tell me how I could avoid the for-loop in the
following function:

function [result] = calp(m)
result=[];
for k=0:m;
result=[result nchoosek(2*m-k,k)];
endfor

thanks in advance
jean


k=[0:m];
n=2*m-k;
arrayfun(@nchoosek,n,k)

for m=5

 arrayfun(@nchoosek,n,k)
ans =

    1    9   28   35   15    1


Regards
Marco



reply via email to

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