How to check from a MEX file if Matlab started with a GUI

I already tried to find the answer to this problem, and asked my question in Matlab Central without an answer. Now I hope that one of you can help me solve my problem. Here is my (improved) question:

The title already pretty well describes what I need to do: I need to check from the MEX file whether Matlab R2013a is running on Linux with or without a graphical interface.

Background: I am running a C / C ++ program (from which I can use sources, but I am not allowed to change them, only to add new files if necessary!) From Matlab. I wrote several (additional) MEX files that allow the program to use mexCallMATLAB to evaluate m files. Now I need to know where I should direct the output of the C / C ++ program, depending on whether Matlab was launched with or without a graphical interface. I need to get this information from a function called from my MEX files. Until now, I can redirect the output of the C / C ++ program by changing the hard-set parameters, but I can already direct it to the correct outputs, that is, to the console without, or to the Matlab command window with a graphical interface.

Prior to R2012x, verification was possible using the C ++ function isatty(), but with R2013a on this verification no longer works, which means that Matlab always starts only from the console, even if it was launched with a graphical interface.

Do any of you know such a feature or other solution to my problem?

Thanks to the people in advance!

Cheers, mindm49907

+4
source share
1 answer

Call usejava('desktop')through mexCallMATLAB. From the docs tousejava :

Syntax

tf = usejava(feature)

...

A Java function specified as one of the following values:

'awt' Java GUI Components in the Abstract Window Set (AWT) components are available.

'desktop' Works interactive desktop MATLAB.

'jvm' Java Virtual Machine (JVM).

'swing' Swing ( GUI- Java Java Foundation Classes).

atDesktop.cpp

#include "mex.h"

bool atMLDesktop()
{
    mxArray *tf(0);
    mxArray *permuteRHSArgs = mxCreateString("desktop");
    mexCallMATLAB(1, &tf, 1, &permuteRHSArgs, "usejava");

    return mxIsLogicalScalarTrue(tf);
}

void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
    plhs[0] = mxCreateLogicalScalar(atMLDesktop());
}

Test

MATLAB:

>> atDesktop
ans =
     1
>> tf = atDesktop
tf =
     1

:

Β» tf = atDesktop
tf =
     0

com.mathworks.mde.desk.MLDesktop.getInstance.getMainFrame MATLAB , , usejava MathWorks.

+2

All Articles