How to interrupt MATLAB IDE when it hangs on displaying very large array?

最后都变了- 提交于 2019-11-29 12:07:24

I found a way, but it's not the best, it requires a change of path and back once to get a handle to the original openvar

function openvar(name,array)
    persistent org_openvar
    if isempty(org_openvar)
        curdir=pwd;
        cd(fullfile(matlabroot,'toolbox/matlab/codetools'));
        org_openvar = @openvar;
        cd(curdir);
    end

    if numel(array)>1e5
        if strcmp(questdlg(sprintf('Opening ''%s'' which has %d elements.\n\nAre you sure? This is gonna take a while!',name,numel(array)), ...
        'Variable editor','Yes','Cancel','Cancel') , 'Yes')
                org_openvar(name,array)
            end
    else
        org_openvar(name,array)
    end
end

getting that handle is the biggest problem, calling it is just fine. If openvar would be built in, you could use the function builtin:

builtin('openvar',name,array)

but this is unfortunately not the case :(
str2func in combination with the complete path also doesn't work, at least I don't get it to work...

The variable editor is launched using the command openvar. To solve your problem you can take advantage of a Matlab quirk that causes functions to be masked by variables with the same name. For example if you create a variable named plot the plot() function stops working.

The solution, although hackish, is to simply create an empty variable named openvar. Then anytime attempt to open the variable editor will fail because the function openvar is being hidden by the variable.

If you want to use the variable editor again simple call clear openvar to delete the variable and the function will be unmasked.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!