splitapply does not retain ME stack

26 次查看(过去 30 天)
Vasco
Vasco 2026-1-15,11:02
评论: Matt J 2026-1-15,13:33
When the function that splitapply throws an error, this line number of this error is not include in the output (matlab2024b)
Example:
T=table([1:3]');
G=findgroups(T);
splitapply(@fun, T, G);
function out = fun(varargin)
ERROR
end
This returns:
Error using splitapply>localsplitandapply (line 196)
Unable to apply the function 'fun' to the 1st group of data.
Error in splitapply (line 135)
varargout = localsplitandapply(fun,dataVars,gdiffed,sgnums,gdim,nargout);
Error in templateLoopOverAll (line 231)
splitapply(@fun, T, G);
Caused by:
Unrecognized function or variable 'ERROR'.
I was expeting that the line number that actually caused that error would be included:
Error in testfile>fun (line 5)
ERROR
Error in testfile (line 3)
fun()
Missing this information makes the debugging of fun very challenging.
How to retrieve this line number?

回答(1 个)

Matt J
Matt J about 9 hours 前
编辑:Matt J about 9 hours 前
Run with Pause on Errors.
Then the code will stop at the offending line:
  1 个评论
Matt J
Matt J about 9 hours 前
Youc an also invoke Pause on Errors from the command line with,
>> dbstop if error

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Text Data Preparation 的更多信息

产品


版本

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by