MATLAB: How can i stop simulation if it takes so long

stop simulation

hi guys how can i stop simulation with a block or something else if time to complete the simulation takes so long.the simulation is part of a code and this must be automatic. thank you with regard

Best Answer

If your simulation has some kind of looping structure in it (e.g. for loop), then you could use the tic/toc functions something like this:
x = 0;
% Simulation starts here. (Using a while loop that is always true, to mimic a long-running simulation.)
tic
while true
x = x+1;
if toc > 5
break
end
end
last_x = x
This "simulation" will halt if it runs for more than about 5 seconds.