Hi,
In case you only want to break the inner for loop, you can try it this way
output=[];
k = 1;
for z = 1:10;
in1 = input1(k);
in2 = input2(k);
v=1;
for t = 0:0.1:5;
var1(v,k) = a;
var2(v,k) = b;
out = [a b];
limit = norm(out - in1);
if limit < a
break;
end
output = [output; out];
v=v+1;
end
z=z+1
end
In case you want to break both the inner and outer for loops, you can try it this way
output=[];
k = 1;
flag=0;
for z = 1:10;
in1 = input1(k);
in2 = input2(k);
v=1;
for t = 0:0.1:5;
var1(v,k) = a;
var2(v,k) = b;
out = [a b];
limit = norm(out - in1);
if limit < a
flag=1;
break;
end
output = [output; out];
v=v+1;
end
if flag
break; to break outer loop
end
z=z+1
end
You need not increment z after inner for loop since it gets incremented by 1 in the outer for loop every time it runs. In case you want z to increment by n (number other than 1), you can write it as ‘for z=1:n:10’
Best Answer