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

為{幸葍}努か 提交于 2019-11-28 05:43:39

问题


Suppose I'm using the MATLAB IDE and happen to have some very large objects in my workspace (e.g. arrays of 500k+ elements). Now, suppose that I stupidly and accidentally double click on one of these very large variables, which triggers a load to the array editor. Unfortunately, with arrays this big, MATLAB just hangs.

I've tried CTRL+C, CTRL+BREAK, CTRL+D, but none seem able to interrupt the behavior of the IDE. I know I can force matlab to quit, but reading all of those variables into the workspace in the first place takes a lot of time, and I may have unsaved changes in an editor window, etc.


回答1:


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...




回答2:


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.



来源:https://stackoverflow.com/questions/11779511/how-to-interrupt-matlab-ide-when-it-hangs-on-displaying-very-large-array

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