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: Pantxo Diribarne
Subject: Re: [newbie] how to avoid a for-loop
Date: Thu, 18 Dec 2014 22:06:22 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.3.0

Le 18/12/2014 21:38, Jean Dubois a écrit :
2014-12-18 18:23 GMT+01:00 Pantxo <address@hidden>:
Hi,

Does the following help ?

function [result] = calp(m)
   tmp = arrayfun (@(x) nchoosek (2*m-x, x), 0:m,
                          "uniformoutput", false);
   result = cell2mat (tmp);
endfunction
Thank you Pantxo, this works fine, maybe you could tell me what the
use or reason is of: "uniformoutput", false?


thanks
jean


It was a mistake :-), "result = arrayfun (@(x) nchoosek (2*m-x, x), 0:m)" was enough. Here the outputs of "nchoosek" are always scalar so they can be concatenated in a vector, hence "uniformouput" may be true (the default). Whenever the ouputs of the expression/function in arrayfun are non scalar values, the "uniformoutput" must be set to false, and the outputs will be returned in a cell array. See "help arrayfun" for examples.

Pantxo






reply via email to

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