How can I go back to the initial condition and the script will read again from that condition

1 view (last 30 days)
x=randi(5,3);
for i=1:3
sum(x(i,:) == 3)
if ((sum(x(i,:) == 3))==0)
% how can I go back to the initial condition (x=randi(5,3))and the script will read again from that point
else
end
end
disp(x)

Answers (1)

Mathieu NOE
Mathieu NOE on 29 Nov 2020
hello
maybe you van do it this way
each time you need to restart from the initial condition, call the IC function as shown here :
% x=randi(5,3);
x = IC();
for i=1:3
% sum(x(i,:) == 3)
if ((sum(x(i,:) == 3))==0)
% how can I go back to the initial condition (x=randi(5,3))
%and the script will read again from that point
% disp(x)
disp('You hit the target!');
x = IC();
else
end
end
disp(x)
function xic = IC()
xic=randi(5,3);
end

Categories

Find more on Visual Exploration 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!