Tracking failed integral2() inside a for loop

2 views (last 30 days)
I'm running the integral2() function within a `parfor` loop. Occasionally, the integration fails during some iterations, and I receive a warning stating "Integration was unsuccessful" along with information about the error bound. I'm wondering if there's a way to track which iterations encounter this issue and what the corresponding error bounds are, all while still inside the `parfor` loop.
For example, I want something like the following:
integrations = zeros(1,10)
fail_flags = zeros(1,10); %0 for failed integrations, 1 for successful
error_bounds = zeros(1,10)'
parfor i = 1:10
warning('off','all')
[integration, fail_flag, error_bound] = integral2(fun,...);
integrations(i) = integration;
fail_flags(i) = fail_flag;
error_bounds(i) = error_bound;
end

Accepted Answer

Walter Roberson
Walter Roberson on 2 Mar 2024
Just before the integral2() call
warning('');
Just after the integral2 call
[msg, lastID] = lastwarn();
If msg is empty then the integral2() succeeded; otherwise you can examine msg and lastID to determine the success.

More Answers (0)

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Products


Release

R2023b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!