Why can't I use Java in startup.m?
Show older comments
I have multiple monitors, and in my startup.m script, I'm trying to find out which one the MATLAB GUI is in (because I want to set the default figure location to the other monitor). This answer tells me to use the following Java object to get the location of the MATLAB GUI:
pt = com.mathworks.mlservices.MLEditorServices.getEditorApplication.getActiveEditor.getComponent.getRootPane.getLocationOnScreen;
This works great, except when I put it in my startup.m script. I get this warning on the line of code shared above when I start MATLAB, and the rest of my startup.m script doesn't run:
Warning: Executing startup failed in matlabrc.
This indicates a potentially serious problem in your MATLAB setup, which should
be resolved as soon as possible. Error detected was:
MATLAB:structRefFromNonStruct
Dot indexing is not supported for variables of this type.
So is Java not available during MATLAB startup? If not, is there another way to determine which monitor MATLAB is open in?
I'm using MATLAB 9.4.0.813654 (R2018a) on Windows.
Accepted Answer
More Answers (0)
Categories
Find more on Startup and Shutdown in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!