"文本"功能很慢,我的代码瓶颈

Mil*_*ila 5 optimization matlab

我正在处理结构化网格.我只想在图中添加一个类型(m,n)的文本,指示每个节点的索引.也许在未来变量的价值.我使用文本功能.我分析了代码,大部分时间花在了这个函数上.它只是一个101*101网格,如果你增加它,代码基本上卡住了.我已经优化了它,避免了文本和spritnf的循环,但它仍然太慢.此外,一旦创建了绘图,它就会非常卡住,每次平移或缩放都需要几秒钟.请参阅以下最小示例.我还添加了用于显示网格的补丁.(我使用补丁,因为我想为每个单元格绘制一些网格数量,我想保持它一般,以防我移动到具有不规则多边形的非结构化网格.补丁是超快的,但没有问题).有什么建议加快这个吗?谢谢

    %define grid and grid numbering
    DX = 10 ; %=DY
    mmax = 101; %= number of nodes in x
    nmax = mmax %= number of nodes in y
    [ x y ] = meshgrid(0:DX:DX*(mmax-1),0:DX:DX*(mmax-1)); %grid
    [ mMAT nMAT ] = meshgrid(1:mmax,1:nmax); %grid numbering
    %
    %display patch
    %
    cont = 0
    for m=2:mmax
        for n=2:nmax
            cont=cont+1;
            Xpatch(1:4,cont) = [ x(n-1,m-1) ; x(n-1,m) ; x(n,m) ; x(n,m-1) ] ;% ii+1 since it has the BC
            Ypatch(1:4,cont) = [ y(n-1,m-1) ; y(n-1,m) ; y(n,m) ; y(n,m-1) ] ;
            Zpatch(cont) = 1;
        end
    end
    hpatch3 = patch(Xpatch(:,:),Ypatch(:,:),Zpatch(:)');
    %
    % display node indices
    %
    charINPUT = regexp(sprintf('(%d,%d)\n',mMAT(:),nMAT(:)),'(?<=\s*)(\S*)(?=\n)','match'); % use regexp to vectorize sprintf and so avoid slow loops with sprintf 
    text(x(:),y(:),charINPUT(:),'Clipping', 'on');
    set(gcf,'position',[9 40 1350 650])
    set(gcf,'PaperPositionMode','auto')
Run Code Online (Sandbox Code Playgroud)

Mil*_*ila 3

伙计们,我找到了解决方案。hittest如果你设置的话,速度会快 100 倍'off'!!!!我这样做了:

text(x(:), y(:), charINPUT(:), 'Clipping', 'on','hittest', 'off');
Run Code Online (Sandbox Code Playgroud)

我的生活改变了。

谢谢。A。