How to mute the notification of the official function like this?

12 次查看(过去 30 天)
I was trying to compare the working speed of the function that I 'd programed with the official function quadprog.
I looped them for 10000 times to erase the tiny error while testing. However, the notification like that also repeated for 10000 times, which was kind of annoying. I was wondering whether it is possible to get rid of the notification in the command window like that:

采纳的回答

Mrutyunjaya Hiremath
  • Yes, you can suppress the output of the quadprog function and avoid displaying the notifications in the command window. MATLAB provides the optimoptions function to control the display and output options for optimization solvers like quadprog. You can set the 'Display' option to 'off' to suppress the output.
  • Here's how you can modify your code to achieve that:
function timeComparison()
% Disable warnings
warning('off', 'all');
% Define your loop here (10000 iterations)
for i = 1:10000
% Your code here
% Call your custom function
% For example:
% result_custom = your_custom_function(input_arguments);
% Call quadprog function and suppress the output
options = optimoptions('quadprog', 'Display', 'off');
result_quadprog = quadprog(..., options);
end
% Enable warnings back (optional, but recommended)
warning('on', 'all');
end
  • By setting 'Display' to 'off' in optimoptions, the notifications and output from quadprog will be suppressed for all iterations within the loop. After the loop is complete, you can enable warnings again using warning('on', 'all'); if needed.
  2 个评论
Walter Roberson
Walter Roberson 2023-8-1
Note that with quadprog not accepting an initial point, it follows that quadprog twice with the same function and same constraints but different x0 might give exactly the same result each time.

请先登录,再进行评论。

更多回答(0 个)

类别

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

Community Treasure Hunt

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

Start Hunting!

Translated by