Stop an infinite loop with a key
显示 更早的评论
Hey guys, I have this infinite loop and I want to exit the while loop and continue the code when I press the cancel button in the waitbar, but this button isnt working, what can I do?
% Start the module
dev.start();
fprintf('Start of LimeSDR\n');
tic;
start_time=datetime('now','Format','dd-MMM-uuuu HH:mm:ss.SSS');
hWaitbar = waitbar(0,'Receiving Samples', 'Name', 'Progress', ...
'CreateCancelBtn','setappdata(gcbf,''canceling'',1)');
setappdata(hWaitbar,'canceling',0);
while true
% Receive samples on RX1 channel
indRx1 = 1; % index of the last received sample
[samples1, ~, samplesLength1] = dev.receive(Fs*Ts,1);
bufferRx1(indRx1:indRx1+samplesLength1-1) = samples1;
TT=array2timetable(samples1,'SampleRate',Fs,'StartTime',start_time);
writetimetable(TT,'Timetable_Rx1.txt','Delimiter','bar');
type Timetable_Rx1.txt
pause(1);
if getappdata(hWaitbar,'canceling')
% Stop the if cancel button was pressed
disp('Stopped by user');
break;
end
delete(hWaitbar);
end
% Cleanup and shutdown by stopping the RX stream and having MATLAB delete the handle object.
dev.stop();
tempo_rececao=toc;
stop_time=datetime('now','Format','dd-MMM-uuuu HH:mm:ss.SSS');
clear dev;
fprintf('Stop of LimeSDR\n');
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 App Building 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
