Stop an infinite loop with a key
2 views (last 30 days)
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
fprintf('Start of LimeSDR\n');
hWaitbar = waitbar(0,'Receiving Samples', 'Name', 'Progress', ...
% 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;
% Stop the if cancel button was pressed
disp('Stopped by user');
% Cleanup and shutdown by stopping the RX stream and having MATLAB delete the handle object.
fprintf('Stop of LimeSDR\n');
Jan on 22 Jun 2022
Edited: Jan on 22 Jun 2022
You delete the waitbar in the first iteration:
Remove this line. or move it behind the loop.
I cannot imagine what you call "does not work", because if you delete the complete waitbar, there is no button to press at all. Maybe you have some orphaned waitbars from former trials?