Tracking failed integral2() inside a for loop

1 次查看(过去 30 天)
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

采纳的回答

Walter Roberson
Walter Roberson 2024-3-2
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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Startup and Shutdown 的更多信息

产品


版本

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by