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

后端 未结 2 1696
天涯浪人
天涯浪人 2020-12-20 00:22

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 d

相关标签:
2条回答
  • 2020-12-20 00:54

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

    0 讨论(0)
  • 2020-12-20 00:56

    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.

    0 讨论(0)
提交回复
热议问题