79087428

Date: 2024-10-14 19:15:06
Score: 1.5
Natty:
Report link

Note the for loop as shown above has another problem: it will allocate memory for a growing array on the fly. You can save some time by allocating memory for the output array in advance, e.g.

vector_y = zeros(size(vector_x));

before the loop. But the simplest and fastest solution for that task would be

vector_y = vector_x .^ 2; % . denotes element wise operation

Faster by a factor 1000 compared to the loop!

Reasons:
  • No code block (0.5):
  • Low reputation (1):
Posted by: Roland