[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Construct cell array whose elements satisfy a{i}==i
From: |
Bård Skaflestad |
Subject: |
Construct cell array whose elements satisfy a{i}==i |
Date: |
Fri, 11 Mar 2011 12:40:21 +0100 |
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
- Construct cell array whose elements satisfy a{i}==i,
Bård Skaflestad <=