Calling a script from Java using COM

1 view (last 30 days)
Michael Garcia
Michael Garcia on 7 Oct 2014
Commented: Michael Garcia on 7 Oct 2014
I'm having trouble getting my script to execute using the COM api calling from Java. Here's a code snippet:
myMatlabInCom = new ActiveXComponent("Matlab.Application");
myMatlabInCom.invoke("Execute", new Variant("addpath('e:\matlabscripts');");
myMatlabInCom.invoke("Execute", new Variant("addpath('C:\mike\test');");
myMatlabInCom.invoke("Execute", new Variant("cd ('C:\mike\test');");
myMatlabInCom.invoke("Execute", new Variant("mikeWrapper;");
In c:\mike\test there is a mikeWrapper.m script file that has one function called mikeWrapper.
The function is never called. I can do the add path calls, cd and mikeWrapper call in Matlab but not from the COM interface.
Any idea what I might be doing wrong? Seems like this should be easy but I can't seem to get it to work.
Thanks, -Mike
  1 Comment
Michael Garcia
Michael Garcia on 7 Oct 2014
Here's a sample script that shows the same behavior. Just save it as testScript.m and call "testScript" instead of "mikeWrapper" in the same code.
function testScript()
prompt = 'Do you want more? Y/N [Y]: ';
str = input(prompt,'s');
if isempty(str)
str = 'Y';
end
disp('You answered: ');
disp(str);

Sign in to comment.

Answers (0)

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!