m=n=512 Sd=3140; So= 2510; det=1120; A=zeros(360,det); cx=(n)/2;p=det/2; for L=1:1:360
for i=1:m for j=1:n Y=((So-cx)+j); %y-indices of pixel if i<=cx X=cx-i; % x-indices of pixel above r D=p-((X/Y)*Sd); end if i>cx X=i; D=(((i-cx)/Y)*Sd)+p; end wy1=(floor(D)+1)-D; wy2= 1-wy1; ddata=A(L,:); if (D) >1 && (D) <det ima(i,j)=(ddata(1 ,floor(D) )*wy2)+(ddata(1 ,floor(D)+1 )*wy1); end
Here are some comments on your code:
1) As your code stands, the quantity 'L' has no effect whatever on the quantity 'D', so the condition "D>1&D<det" will hold true for the same set of i,j pairs for every value of L. This means that the final contents of 'ima' depend only on the last pass through that outer L-loop. The other 359 passes in the loop are totally wasted, with all their results being subsequently overwritten. I strongly suspect you actually have something quite different in mind here.
2) Where you have the condition i<=cx and i>cx, as you have written it, the result in D is the same in either case, namely
D = p-(cx-i)/(So-cx+j)*Sd
I suspect you meant to reverse the sign in one of these two cases, but if so instead of using the 'if' construct, you could just say
D = p - abs(cx-i)/(So-cx+j)*Sd
D = p + abs(cx-i)/(So-cx+j)*Sd
depending on whichever one it is you meant to have. Either way there is no need for the 'if' here.
3) As Matt Kindig has said, you need to pre-allocate the matrix 'ima' before entering the for-loops. In particular you need to decide what the default contents of 'ima' are to be when nothing from 'ddata' will have been entered, that is, an i,j combination for which D>1&D<det is false for every L.
4) As the code stands now using only L = 360, it can be entirely vectorized with all for-loops eliminated. Whether that would remain true with all values of L being involved in accordance with comment 1), would depend on the nature of the change made to accomplish that.
Play games and win prizes!Learn more