Comparing data from previous iteration with data from this iteration
1 view (last 30 days)
Show older comments
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 Comments
Answers (2)
Iain
on 17 Jun 2013
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 Comments
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!