Octave calculations is too slow specially when you deal with scientific calculations that can span a very very large matrix, even just iterating. I have to vectorize it to speed up the calculation.
Vectorizing a 1xn matrix would just be easy by following
for i = 1:n if (a(i) > 5) a(i) -= 20 endif endfor
But I dont have any clue when the matrix becomes nxm. My sample code is shown below.
segs = 1000000; r_int = 100; r_ot = 2000; x = linspace (0, 1000, segs); y = linspace (0, -1000, segs); [xx, yy] = meshgrid (x, y); circ = xx.*yy; circ_matrix = zeros(segs,segs); #this needs vectorization for j = 1:segs for i = 1:segs if((r_int<=circ(i,j)) &&(circ(i,j)<=r_ot)) circ_matrix(i,j)=1; endif; endfor; endfor;
I have marked the code that needs vectorization
Some things tried:
but did not work