Comparing data from previous iteration with data from this iteration
조회 수: 1 (최근 30일)
이전 댓글 표시
I want to terminate my loop when the difference between two iteration has an L2 norm of less than 0.1% I thought this was done in the following way;
Diff = 0.5; Data(0) = 0; While Diff >0.1 Adashpad = padarray(Adash,[1 1 1]);
Data(i) = Adash - sigma.*NORMALISED;
Diffpart1 = (Data(i) - Data(i-1));
Diffa = Diffpart1(:);
part1 = sqrt(sum(abs(Diffa)).^2);
Adashpart2 = Adash(:);
part2 = sqrt(sum(abs(Adashpart2)).^2);
Diff1 = (part1./part2)*100;
Adash = Data;
end
However, this throws up the following error;
In an assignment A(:) = B, the number of elements in A and B must be the same.
Error in ==> reconstruction_of_image3 at 266 Data(i) = Adash - sigma.*NORMALISED;
Also can I just check that by assigning Adash = Data at the end of my while loop it will cause Data to be used in place of Adash at the top of my loop and so it will go through the processes again. I have not used many while loops so was a bit confused on how to get them to repeat.
Many thanks for any help you can give
댓글 수: 0
답변 (2개)
Iain
2013년 6월 17일
Adash = Data; copies the WHOLE of data into Adash. When you then start the loop at the top again, and "Data(i) = Adash - s...", tells matlab to then put the whole of the old "Data" into a single element of data.
while Diff > 0.1
old = current;
current = ... some recalculation
Diff = (old / current) * 100;
end
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!