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!