Search code examples
javamatlabmatlab-deploymentmatlab-compiler

Undefined variable "modem" or class "modem.pskmod" when calling from java


I have written a code in matlab which modulate and demodulate some signals. I deploy them using deploytool and the .jar works in one application without GUI but gives me the Undefined variable "modem" or class "modem.pskmod". in an application with GUI.

Basically, what I want to know what will cause this error to occur as I have look around, I don't find much documentation on this error.

As I don't understand why it work in one application but fails in another when the code I use is almost similar when calling the method.


Solution

  • Ok, after much testing and comparing the difference between an application WITHOUT a GUI and an application WITH a GUI. I found a solution to my problem.

    As an application without a GUI run init the method from the start of the application (there is only one thread)
    import matlabFunction.*;
    public static void main(String[] args) {
    matlabFunction test = new matlabFunction(); test.runFunction(1, lstABC.toArray());
    }

    But in my code with GUI I run the init method from within the JFrame (main() contain my init code) which is inside the EDT

    public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() {

            public void run() {
                try {
    
                    new main();
                } catch (Exception p) {
                }
            }
        });
    }  
    

    The error occur with the above way to init the matlab method. But if I change way of calling the init method as below, the error is solve.

    public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() {

            public void run() {
                try {
                    matlabFunction test = new matlabFunction();
                    new main(test);
                } catch (Exception p) {
                }
            }
        });
    } 
    

    So, I believe the reason for my problem is not calling the init method from the "first" thread that starts the application.