matlab GOTO(某种程度上)

matlab GOTO (sort of)

我有一个很长的脚本,调用了许多其他脚本,这些脚本吐出了很多数字。

出于调试目的,我认为如果 - 当单击图片时 - 编辑器转到特定行,将会很有用。有谁知道这是否可能?

我想我可以实现类似的东西

A=[];
figure
plot(x)

A=ginput(1)

if A~=[]
  goto(pointer,line)
end

问题是模型制作完成后才有效。当我查看最终错误的数字时,还没有结束分析。

换句话说:有没有一种方法可以通过单击图形转到代码的特定行?

N.B。有关 GOTO 的实现,请参阅 (GOTO FileExchange)

尝试将 opentoline 函数与回调结合使用。像

plot(1:10); % A simple plot
set(gcf,'ButtonDownFcn',@(h,e)opentoline('YourFunctionName.m',LineNumber));

在这种情况下,当您单击图形(不是轴或任何标签,而是图形的灰色部分)时,m 文件将在编辑器中打开到指定的行。

如果您想以编程方式确定行号,请执行以下操作

plot(1:10)
st = dbstack;
set(gcf,'ButtonDownFcn',@(h,e)opentoline(st(1).file,st(1).line-1));

你可以使用这个undocumented function:

f = figure;
uicontrol ( 'string', 'open "str2double.m" @ 200', 'callback',  @(a,b)opentoline(which('str2double.m'),200), 'position', [100 100 400 50] )

它适用于我的 r2015a