Repeating a sequence of code multiple times in a for loop with random intervals in between
1 次查看(过去 30 天)
显示 更早的评论
I want to repeat the following code 150 times with 500-800 milliseconds in between (i.e. I want the iterations to be spaced apart randomly, with each spacing being between 500 and 800).
rec=@(x) (x)>=0.75
j = (0 : 0.01 : 29);
k = sin(j);
f = rec(k);
[a,b]=find(f~=0);
N=length(b);
s=0.15;
f=double(f);
f(b)=1+s*rand(1,N);
plot(j,f);
axis([0 29 0 2])
0 个评论
采纳的回答
Walter Roberson
2020-10-19
rec=@(x) (x)>=0.75;
for counter = 1 : 150
j = (0 : 0.01 : 29);
k = sin(j);
f = rec(k);
[a,b]=find(f~=0);
N=length(b);
s=0.15;
f=double(f);
f(b)=1+s*rand(1,N);
plot(j,f);
axis([0 29 0 2])
drawnow
delay = 500+300*rand();
pause(delay/1000);
end
2 个评论
Walter Roberson
2020-10-20
You cannot store delays. Delays are something that happen in real time. MATLAB does not have any way to allow you to submit a list of points to plot with built-in delays at particular points in the output.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Line Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!