help-octave
[Top][All Lists]
Advanced

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

Re: Construct cell array whose elements satisfy a{i}==i


From: Primoz PETERLIN
Subject: Re: Construct cell array whose elements satisfy a{i}==i
Date: Fri, 11 Mar 2011 13:34:14 +0100

Perhaps num2cell(1:n)?

Regards, Primoz

2011/3/11 Bård Skaflestad <address@hidden>:
> All,
>
> For initialisations purposes in an algorithm I'm implementing, I need to
> construct an n-element cell array whose i'th element is just the scalar
> 'i'.  In other words, given a positive integer 'n', I'm trying to build
> the array (n=5 for illustration purposes)
>
>   a = {1, 2, 3, 4, 5}
>
> So far the simplest alternatives seem to be (variations of)
>
>   a = arrayfun (@(i) i, 1:n, "UniformOutput", false)
>
> and
>
>   a = mat2cell (1:n, 1, ones ([1, n]))
>
> Are there any other, possibly more direct, constructions?
>
>
> Sincerely,
> --
> Bård Skaflestad <address@hidden>
> SINTEF ICT, Applied Mathematics
>
> _______________________________________________
> Help-octave mailing list
> address@hidden
> https://mailman.cae.wisc.edu/listinfo/help-octave
>


reply via email to

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