continue and return in a loop

1 view (last 30 days)
Dion Theunissen
Dion Theunissen on 3 Mar 2021
Answered: darova on 3 Mar 2021
Hi,
See my script below. I added in this script what I exactly want.
So if a value is what i want it is, go out of the loop and continue the script.
How can I fix this?
fullfilename = fullfile(RCA(30).folder, RCA(30).name);
for k = 1:length(RCA)
fullfilename = fullfile(RCA(k).folder, RCA(k).name);
thisData = readmatrix(fullfilename, 'Range', 2, 'Delimiter', ',');
%% Run ICP (standard settings)
for i = 2:100
[Ricp Ticp ER weight] = icp(M, D, i);
% Transform data-matrix using ICP result
Dicp = Ricp * D + repmat(Ticp, 1, n);
set(0, 'CurrentFigure', f1)
ER1 = ER(end-1) - ER(end)
end
%% this is the point where i need to add something:
%% If ER1 < 0.005 it has to continue outside the i loop.
%% So if ER < 0.005 continue at plot3(D..... otherwise continue for i = 3 and so on.
plot3(D(1,:),D(2,:),D(3,:),'bo',M(1,:),M(2,:),M(3,:),'-');
hold on
xlim([-40 70]);
ylim([-50 50]);
zlim([-90 10]);
ER2(k,1)=ER(end);
ER2(k,2) = ER(end-1)-ER(end);

Accepted Answer

darova
darova on 3 Mar 2021
Here is the solution
for i = 2:100
[Ricp Ticp ER weight] = icp(M, D, i);
% Transform data-matrix using ICP result
Dicp = Ricp * D + repmat(Ticp, 1, n);
set(0, 'CurrentFigure', f1)
ER1 = ER(end-1) - ER(end)
if ER1 < 0.005
break
end
end
%% this is the point where i need to add something:
%% If ER1 < 0.005 it has to continue outside the i loop.

More Answers (0)

Categories

Find more on Graphics Object Programming in Help Center and File Exchange

Products


Release

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!