Setting the name of the Matlab Command Window

조회 수: 13 (최근 30일)
Norbert Thek
Norbert Thek 2022년 10월 20일
답변: Zhuohe Liu 2023년 2월 17일
Hello
for an automatisation process I start Matlab(Simulink) from the commandline, and for this purpose with the setting "-nodesktop"
I will get a Command window, which looks something like this
screenshot  of a Matlab Command Windows
Is it possible to add something to the window title, to make it easier to find the proper window if several are started in parallel
Something like the filename, currenworking dir or even a "generic" text would be nice.
Via commandline, or via m-code

채택된 답변

Benjamin Kraus
Benjamin Kraus 2022년 10월 21일
편집: Benjamin Kraus 2022년 10월 21일
No, there is no way to modify the title of the MATLAB command window.
  댓글 수: 1
Norbert Thek
Norbert Thek 2022년 10월 24일
Not what I hoped for, but at least I have the information now.
Thanks

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Zhuohe Liu
Zhuohe Liu 2023년 2월 17일
I am looking for the solution of the same question. I tested and the following solution works:
  1. Copy and paste the code to e.g. 'setWindowTitle.cpp';
  2. Compile the cpp to a MEX function by calling mex setWindowTitle.cpp in MATLAB. (Run mex -setup to setup the compiler).
  3. Call the function directly as the file name: e.g. setWindowTitle('New Window Title') or you can wrap it as a method of a class or a package function.
//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.
}
}

카테고리

Help CenterFile Exchange에서 MATLAB Compiler에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by