Here a simple Matlab function that takes a String as input.
function dispStr(input_string)
fprintf('This is my input %s\n',input_string);
end
Next I'll compile it to get the corresponding dispStr.jar.
- Apps >> Library Compiler
- Type: Java Package
- Exported functions (main file): dispStr.m
- Now create the “package”
Test that it runs in Windows:
C: >java –classpath "C:\MATLAB\R2014b\toolbox\javabuilder\jar\javabuilder.jar";C:\MATLAB\R2014b\work\dispStr\for_testing\dispStr.jar dispStr.Class1 'test'
This returns: This is my input test
Now we will test the “string input” using the MCR on an Ubuntu system. We assume that the MCR has been installed and tested with the magicsqr package successfully (see here for details). Copy the for_testing folder to a shared folder (between Windows and Ubuntu VM).
Execute the following commands:
sudo -i
export LD_LIBRARY_PATH="/opt/MCR/v84/runtime/glnxa64:/opt/MCR/v84/bin/glnxa64:/opt/MCR/v84/sys/os/glnxa64:${LD_LIBRARY_PATH}"
export XAPPLRESDIR="/opt/MCR/v84/X11/app-defaults"
java -classpath "/opt/MCR/v84/toolbox/javabuilder/jar/javabuilder.jar:/media/sf_shared/for_testing/dispStr.jar" dispStr.Class1 'test'
This returns the following exception:
Error using eval
Undefined function or variable 'test'.
com.mathworks.toolbox.javabuilder.MWException: Undefined function or variable 'test'.
Exception caught: java.lang.NullPointerException
Note: You would get the same error in Windows if you use double quotes for the string input, e.g. dispStr.Class1 "test".
Is there a different way to pass string variables in Ubuntu?