now i try to expian better
ok. now what do you define as a successful solution? Your initial, very simple but effective script with loops works. it should work for very large arrays. It may not be the fastest on octave. Matlab is probably much faster because it has a working JIT (Just In Time) compiler that knows how to optimize loops.
In the script that I threw together, it removed the loops but only sped things up by about 30% for small cases. I suspect that might increase as the data size increases, but as you have seen, we're trading memory for speed. We can only hold so much data at one time. Your looping case holds very little. Projection operations to parallelize operation are not memory efficient. They multiply, and often duplicate, the data in memory to try to operate on it faster in parallel. For any solution and a particular data set you could tabulate speed and peak memory requirement to compare them and decide which is best.
What are your requirements for 'success' on the homework? You've created two working algorithms. Is vectorization or speed a requirement?