MATLAB: How to reiterate the function automatically if the code stops working because the internet disconnected

errorwebxmlread

Hello,
I want to get weather data from a URL given below:
xdom = xmlread('http://api.openweathermap.org/data/2.5/forecast? q=Texel,NL&mode=xml&APPID=f3e1e8697d3d20e5d91f193ef02e4846')
Now my whole code is running properly, but due to bad internet connection my code stopped. To safeguard my whole code that it doesn't happen again, I want to develop a code which will help in reiterating the code after every 30 seconds until the internet connection is restored. Can someone help me with the same.

Best Answer

How does this code stop? With an error message? Then TRY-CATCH is a direct solution:
success = false;
while ~success
try
xdom = xmlread('...');
success = true;
catch ME
disp('Failed:');
disp(ME.message);
pause(30);
end
end
Related Question