Thursday, May 29, 2008

MATLAB Warning: Initializing Handle Graphics failed in matlabrc.

Hello Folks!
I'm finally here again though my spare time is almost nonexistent, to post a solution about a "MATLABonLinux" issue.

Yesterday after the month-long reorganization of my disks and data on my Desktop PC with the reinstallation of ArchLinux as OS... and in the same time after the failure of my old Laptop with the migration to another old laptop of all data and the installation from scratch of ArchLinux also there...
I installed MATLAB R2007a on ArchLinux under a 2.6.25 kernel, with JRE 1.6.0_05-b13 and Xorg 1.4.0.90

After a clean installation and a clean setup with the install_matlab script you have to run after the graphic install... I opened the program to see this message as output of the initialization process as it was just before the prompt:

Warning: Initializing Handle Graphics 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:badsubscript
Attempted to access monitors(1,:); index out of bounds because size(monitors)=[0,4].

In matlabrc at 108


I began to search the Internet about this problem, but I found only references to a locale or pathdef problem I hadn't.

I tried to understand who called who in the initialization and going to matlabrc.m line 108 I found the call to another configuration/initialization script: hgrc.m
(All these configuration files are locate in your $MATLAB/toolbox/local/ directory where $MATLAB is your MATLAB installation path).

In hgrc.m I found the call to "get" to assign the matrix monitors who creates the issued that brought to the error.

In the MathWorks techincal documentation site you can find all the "Handle Graphics Object Properties" at this page
If you easily click on the root category of the properties in the list on the left you will find the very "MonitorPosition" property whose call led to an initialization error.

Actually the "get" call in hgrc.m assign to monitors the result of the MonitorPosition parameters that the MATLAB system recognized.

Probably due to a Java vs X incompatibility (I can't install FemLab because of a Java - X version to version issue) the get function returns and empty matrix for the call about MonitorDefinition

The solution is quite brutal. I read what data should output the get(0,'MonitorPosition') call, and I assigned them directly to the monitor variable modifying the hgrc.m script.

As you can find in the previous linked documentation page:

MonitorPosition

[x y width height;x y width height]

Width and height of primary and secondary monitors, in pixels. This property contains the width and height of each monitor connnected to your computer. The x and y values for the primary monitor are 0, 0 and the width and height of the monitor are specified in pixels.

The secondary monitor position is specified as

x = primary monitor width + 1
y = primary monitor height + 1

Querying the value of the figure MonitorPosition on a multiheaded system returns the position for each monitor on a separate line.

v = get(0,'MonitorPosition')
v =
x y width height % Primary monitor
x y width height % Secondary monitor

Note that MATLAB sets the value of the ScreenSize property to the combined size of the monitors



The monitors array for a 1024x768 monitor as mine should be:

monitors = [0,0,1024,768;1025,769,1024,768];


and for a 1280x1024 monitor as my desktop:

monitors = [0,0,1280,1024;1281,1025,1280,1024];



So in the end I commented this line in hgrc.m:

monitors = get(0, 'MonitorPosition');


inserting a '%' character before the line... and I added the manual assign of the correct matrix to the monitors variable:

monitors = [0,0,1024,768;1025,769,1024,768];


After this workaround my MATLAB starts without any problem and displays every figure correctly.

That's all folks.. I hope this solution is useful for someone...

Keep On Hacking!
bYe,
Andy

About This Blog

About This Blog

  © Blogger template Brooklyn by Ourblogtemplates.com 2008

Back to TOP