using GetChar on Matlab 6 for Windows

Chien-Chung Chen has reported that the psychtoolbox function "GetChar"
when called from MATLAB 6.0 for Windows hangs Matlab. Here is a
short explanation of that problem and how to avoid it.

The default frontend for Matlab 6 on Windows is written in Java and
executes in a Java Virtual Machine (JVM). The JVM does not interact
well with psychtoolbox dlls (mex files) which access the windows event
queue. However, you can run a Matlab 6 command window without using
the java stuff. To do that, invoke Matlab with the -nojvm option

For example, because I have installed the Matlab executable here:
C:\matlabR12\bin\win32\matlab.exe

To launch Matlab I type at the Windows command line:
C:\matlabR12\bin\win32\matlab.exe -nojvm

Typing that (and then hitting the enter key) to launch Matlab is
inconvenient. Instead, you can modify a shortcut (a thing which Mac
users would call an alias) to launch Matlab with the -nojvm option.
In Windows 2000, right-click on a Matlab shortcut icon and select the
properties item from the pop-up menu. Under the 'shortcut' tab of the
properties window, find the field named 'target'. The content of this
fields specifies the path to the matlab executable. Append ' -nojvm'
to the path and click the 'ok' button to close the properties window.
(Note the space before before the hyphen in ' -nojvm'.)

Henceforth, when you double-click on that shortcut to launch Matlab it
will launch without the Java stuff. Be careful, if you launch Matlab
some other way, it will not launch with the -nojvm option.

Some people launch Matlab from the Start menu. The Matlab entry in
the Start menu tree is a Windows shortcut which you can modify as
described above. In Windows 2000 that start menu shortcut for Matlab
is in:
C:\Documents and Settings\All Users\Start Menu\Programs\MATLAB Release
12

These instructions might be slightly different for other varieties of
Windows. For example, in windows 98 the start menu shortcut is in:
C:\Windows\Start Menu\Programs\Matlab.

You can find all Matlab shortcuts by using Window's find utility from
the Start menu. You can also relabel shortcuts to identify them as
the -nojvm and regular variety. You can create new shortcuts by
right-clicking on a shortcut or on the Matlab executable and selecting
"Create Shortcut" from the pop-up menu. (Shortcuts created from other
shortcuts point to original executable, not to the shortcut).

GetChar will get characters if you use -nojvm, but be warned that
GetChar still occasionally misses some kepresses.

Allen




>Date: Mon, 2 Apr 2001 14:28:02 -0700 (PDT)
>From: Chien-Chung Chen <ppanthers@...>
>Subject: PsychToolbox bug report
>To: David Brainard <brainard@...>
>
>David,
>
>'getchar' is not compatible with MATLAB 6.0 (Release
>12). It hangs MATLAB. The 'screen' seems working fine
>so far. BTW. Is there any progress on "playsound" for
>Windows? I wrote a small utility to work around the
>problem, but I would be happy that it is in the
>toolbox so that I can make sure my codes work the same
>under Windows or Mac.
>
This is a follow-up to my previous message about the -nojvm fix for getchar under
Matlab 6.

You can't edit .m files from the Matlab environment if you run Matlab with the
-nojvm option. One way around this is to run two instances of Matlab, one with
and one without -nojvm. Use the -nojvm instance to invoke .m files and use the
other instance to edit .m files.

Allen



"Allen W. Ingling" wrote:

> Chien-Chung Chen has reported that the psychtoolbox function "GetChar"
> when called from MATLAB 6.0 for Windows hangs Matlab. Here is a
> short explanation of that problem and how to avoid it.
>
> The default frontend for Matlab 6 on Windows is written in Java and
> executes in a Java Virtual Machine (JVM). The JVM does not interact
> well with psychtoolbox dlls (mex files) which access the windows event
> queue. However, you can run a Matlab 6 command window without using
> the java stuff. To do that, invoke Matlab with the -nojvm option
>
> For example, because I have installed the Matlab executable here:
> C:\matlabR12\bin\win32\matlab.exe
>
> To launch Matlab I type at the Windows command line:
> C:\matlabR12\bin\win32\matlab.exe -nojvm
>
> Typing that (and then hitting the enter key) to launch Matlab is
> inconvenient. Instead, you can modify a shortcut (a thing which Mac
> users would call an alias) to launch Matlab with the -nojvm option.
> In Windows 2000, right-click on a Matlab shortcut icon and select the
> properties item from the pop-up menu. Under the 'shortcut' tab of the
> properties window, find the field named 'target'. The content of this
> fields specifies the path to the matlab executable. Append ' -nojvm'
> to the path and click the 'ok' button to close the properties window.
> (Note the space before before the hyphen in ' -nojvm'.)
>
> Henceforth, when you double-click on that shortcut to launch Matlab it
> will launch without the Java stuff. Be careful, if you launch Matlab
> some other way, it will not launch with the -nojvm option.
>
> Some people launch Matlab from the Start menu. The Matlab entry in
> the Start menu tree is a Windows shortcut which you can modify as
> described above. In Windows 2000 that start menu shortcut for Matlab
> is in:
> C:\Documents and Settings\All Users\Start Menu\Programs\MATLAB Release
> 12
>
> These instructions might be slightly different for other varieties of
> Windows. For example, in windows 98 the start menu shortcut is in:
> C:\Windows\Start Menu\Programs\Matlab.
>
> You can find all Matlab shortcuts by using Window's find utility from
> the Start menu. You can also relabel shortcuts to identify them as
> the -nojvm and regular variety. You can create new shortcuts by
> right-clicking on a shortcut or on the Matlab executable and selecting
> "Create Shortcut" from the pop-up menu. (Shortcuts created from other
> shortcuts point to original executable, not to the shortcut).
>
> GetChar will get characters if you use -nojvm, but be warned that
> GetChar still occasionally misses some kepresses.
>
> Allen
>
> >Date: Mon, 2 Apr 2001 14:28:02 -0700 (PDT)
> >From: Chien-Chung Chen <ppanthers@...>
> >Subject: PsychToolbox bug report
> >To: David Brainard <brainard@...>
> >
> >David,
> >
> >'getchar' is not compatible with MATLAB 6.0 (Release
> >12). It hangs MATLAB. The 'screen' seems working fine
> >so far. BTW. Is there any progress on "playsound" for
> >Windows? I wrote a small utility to work around the
> >problem, but I would be happy that it is in the
> >toolbox so that I can make sure my codes work the same
> >under Windows or Mac.
> >
>
> To Post a message, send it to: psychtoolbox@...
>
> To Unsubscribe, send a blank message to: psychtoolbox-unsubscribe@...
>
> psychtoolbox web site: http://color.psych.ucsb.edu/psychtoolbox/
>
> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/