我在循环中使用gmdistribution.fit
来获取大约100,000
数据,每个数据都有250
样本。
当我运行脚本时,会收到警告,
Warning: Failed to converge in 100 iterations for gmdistribution
with 2 components
> In @gmdistribution\private\gmcluster at 183
In gmdistribution.fit at 174
有没有一种方法可以计算警告(类似于
catch
),所以我可以知道其中有多少没有收敛?这是关于如何计算警告消息的一般问题,
GMM
只是一个示例。
最佳答案
如果您使用的命令每次调用仅输出一个警告,则可以使用以下命令:
warningCounter = containers.Map();
while(youComputeStuff)
functionThatGivesASingleWarning();
[msgstr, msgid] = lastwarn;
lastwarn(''); % Reset lastwarn
if ~isempty(msgstr);
if isKey(warningCounter, msgstr)
warningCounter(msgstr) = warningCounter(msgstr)+1;
else
warningCounter(msgstr) = 1;
end
end
end
disp([warningCounter.keys; warningCounter.values])
如果没有这种控制流,因为您的函数可以在每次调用时发出多个警告,则可以考虑覆盖内置的
warning
并使用一些全局计数变量。
关于matlab - 在MATLAB中计算警告消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27469421/