I have written a small code in Octave and part of it is checking whether values in the first rows of two matrices are equal, and if so, adding the value of the second row of the second matrix to the value of the second row of the first matrix.
This is that part of the code that I have written:
X=0:0.5:BeamLength; X(2,:)=0; x=1; #row number in matrix X y=1; #row number in matrix PositionLoadArray while y<=columns(PositionLoadArray) if PositionLoadArray(1,y)==X(1,x) X(2,x)=X(2,x)+PositionLoadArray(2,y); y=y+1; x=1; else x=x+1; endif endwhile
The loop runs and works perfectly for small sets (i.e. where the total number of columns for X and PositionLoadArray (max. values of x and y, respectively) are small). But the loop takes too long to be executed with larger values.
How can I reduce the execution time and get the same result?