MATLAB:设置非java命令窗口的标题

时间:2013-04-18 18:57:39

标签: windows matlab

问题

如何在没有桌面和没有java的情况下启动MATLAB窗口的命令窗口标题?

  • Matlab ver of primary interest:2012a&后
  • 操作系统需要:Windows(XP)主要;一般更喜欢的东西
  • 理想解决方案:在由下面描述的“mat”函数生成的结果窗口中设置标题。
  • 替代解决方案:在由下面描述的“matj”函数生成的窗口中设置命令窗口标题。

背景

我有匿名函数来启动“准系统MATLAB”窗口(每个窗口都从我的MATLAB主窗口终端执行。

mat  = @(sCmd) system(['matlab.exe -nodesktop -nosplash -nojvm -r "' sCmd ';" &']);
matj = @(sCmd) system(['matlab.exe -nodesktop -nosplash -r "' sCmd ';" &']);

“matj”窗口比“mat”产生的内存密集程度更高。

我知道在启用java的窗口中设置标题的技巧,例如我的以下(奇怪的是,它在“matj”窗口中不起作用):

cmdtitle = @(sT) com.mathworks.mde.desk.MLDesktop.getInstance.getClient('Command Window').getTopLevelAncestor.setTitle(sT)

为什么我需要这个/我正在做什么

我从“主”MATLAB窗口(完全加载java和其他铃声/口哨声)中将内存密集型非绘图MATLAB任务分配给这些准系统窗口。将标题设置为这些将允许我给他们一个关于该窗口分配任务的可视标记。

此外,能够在这些准系统窗口中展开显示文本缓冲区会很有帮助(似乎它们仅限于我计算机上的~500行)。标题设置问题的解决方法是在准系统窗口显示后向终端显示字符串,但有限的缓冲区会阻止第一行保持不变。

我们非常感谢有关更好/替代实现这些目标的方法的建议,以及您在阅读/回答时的时间。谢谢你&美好的一天。

1 个答案:

答案 0 :(得分:2)

通过它的声音,你正在做类似于批处理的事情。您可能需要查看Matlab Parallel Computing Toolbox。这个&的最新版本Matlab允许您将计算机视为一个小型计算群集,并为其启动批处理作业,这样可以很好地解决您的问题。

或者,如果您没有获得许可证,您可以使用windows api路径设置窗口标题,并将其包含在mexFunction中。由于它很有趣,我已经将一些代码一起攻击了:

//Include the windows api functions
#include <Windows.h>
//include the matlab mex function stuff
#include "mex.h"

DWORD processID; //the process id of the current matlab

//Callback function, this is the bit that sets the window text
BOOL CALLBACK SetTitleEnum( HWND hwnd, LPARAM lParam ) {    
    DWORD dwID ;
    //get the process of the window this was called on
    GetWindowThreadProcessId(hwnd, &dwID); 
    //if it is our matlab instance, set the title text
    if(dwID == processID) SetWindowText(hwnd, (const char*) lParam);
    return true;
}

void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) 
{
    //get the process id of this instance of matlab
    processID = GetCurrentProcessId(); 

    if (nrhs > 0) { //if we have been given a title
        char * title = mxArrayToString(prhs[0]); //get it as a char* string     
        //get all open windows and call the SetTitleEnum function on them
        EnumWindows((WNDENUMPROC)SetTitleEnum, (LPARAM) title);        
        mxFree(title);//free the title string.
    }
}

我使用Visual Studio 2010 Express在Matlab中编译了上述代码,它在我受限制的命令行版本和普通的完整桌面Matlab中都运行良好。

相关问题