How to limit number of repetition
2 次查看(过去 30 天)
显示 更早的评论
I would need to run this code a specific number of time only (lets say n=30) and at the 30th times the user press on the keyboard, the program stops and creare a text file with the "fr" value reached at the 30th trial.
Here is my code so far:
global p
esc=0;
fr = 20;
while esc ~= 27
d.write(NISignal(fr))
esc = double(p);
if p == '1'
fr = fr+1;
else
fr = fr-2;
end
end
function s = NISignal(freq)
global nxsec dur p
s = 2.6 + 1/4.5*cos(linspace(pi,(2*pi*freq*dur)+pi,nxsec*dur)');
plot(s);
text(1000,6.7,string(freq))
if waitforbuttonpress
p = get(gcf, 'CurrentCharacter');
end
采纳的回答
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!