Octave use of iteration (start:step:end)
<p>Let's say I have an array <code>A = [1 2 3 4 5 6 7 8 9 10]</code>. I want to iterate through it and do something with each number.</p>

<p><code>A(start:step:end)</code> -> since I want to iterate with step <code>1</code> I use <code>A(1:10)</code>. </p>

<p>Question here is, how can I use that iteration? In C++ you would do</p>

<pre class="lang-cpp prettyprint-override"><code>for (int i = 0; i &lt; 10; i++)
{
    //DO SOMETHING
}
</code></pre>

<p>I've spent 4 hours searching how to use that iteration. I have not found a single  explanation to such a trivial thing: passing block of code to actually do something with numbers. Don't even know how to use current index (i.e., <code>i</code> in C++).</p>

<p>I have my function in Octave <code>f = @(variable) (...)</code>, however when I call <code>f(A(1:10))</code> it is not really passing each number to the function but rather finishes iteration and then executes function.</p>

<p>I'd expect something like</p>

<pre><code>A(1:10) (DO SOMETHING WITH EACH NUMBER)
</code></pre>

<p>or in my example</p>

<pre><code>A(1:10) ( f(INDEX) )
</code></pre>

<p>but that does not seem to work either.</p>

<p>I know Octave has a built-in for loop but in my case it is too slow.</p>

<p>That was simplified explanation, here is more advanced.
I want to multiply matrix <code>A</code> in such way that one matrix starts iteration with <code>1</code> and the other one with <code>2</code> (e.g., <code>A(1:end-1).*A(2:end)</code>) and use each multiplied number in my custom function.</p>