× {{alert.msg}} Never ask again
Get notified about new tutorials RECEIVE NEW TUTORIALS

initialize 2-D array with values based on index oneliner

Ray Phan
Jul 09, 2015
<p>Another approach is to use <a href="http://www.mathworks.com/help/matlab/ref/hankel.html" rel="nofollow"><code>hankel</code></a>:</p> <pre><code>&gt;&gt; n = 5; &gt;&gt; hankel(1:n, n:2*n-1) ans = 1 2 3 4 5 2 3 4 5 6 3 4 5 6 7 4 5 6 7 8 5 6 7 8 9 </code></pre> <p>This tip was originally posted on <a href="http://stackoverflow.com/questions/31252215/initialize%202-D%20array%20with%20values%20based%20on%20index%20oneliner/31252643">Stack Overflow</a>.</p>
comments powered by Disqus