This question is closed. Reopen it to edit or answer.
Simple Question about Optimization of Nested IF-FOR loops
1 view (last 30 days)
Show older comments
Closed: MATLAB Answer Bot on 20 Aug 2021
Does any one know how to optimize this code so that it runs faster:
Your help is much appreciated! Thanks a lot!
Is 'iPointsinSlice' a scalar? If so and if it is not positive, nothing will happen here.
Next, don't you mean "m+(l-1)*iNX+(i-1)*iNX*iNY" as the index to 'DoseCubeU'? As it stands it will vary from 1+iNX*iNY to iNX*iNY*iNZ+iNX*iNY. Assuming my guess is correct, do this:
if iPointsinSlice > 0
t = repmat(SliceMaskUr==1,1,1,iNZ);
DoseCubeU(t) = (100/RX_Dose)*SumDose(t);
In case 'iPointsinSlice' is not a scalar you will have to correct your code before we can see how to handle it.
Sorry! It should have been:
t = repmat(SliceMaskUr==1,[1,1,iNZ]);
Andrei Bobrov on 18 Jun 2013
Edited: Andrei Bobrov on 19 Jun 2013
DoseCubeU = bsxfun(@times,100*SumDose/RX,SliceMaskUr==1);
s = SliceMaskUr(end:-1:1,end:-1:1);
tt = cumsum(cumsum(s),2);
t1 = flipud(any(tt,2));
t2 = fliplr(any(tt));
DoseCubeU = bsxfun(@times,100*SumDose(t1,t2,:)/RX_Dose,SliceMaskUr(t1,t2));
Iain on 18 Jun 2013
DoseCubeU(NY,NX,NZ) = 0; % or any suitable initialisation
DoseCubeU(SliceMaskUr(m,l)==1,:) = 100*SumDose(SliceMaskUr(m,l)==1,:);
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!