Implicit java object variable initializaton or declare
1 次查看(过去 30 天)
显示 更早的评论
A function Miji() load a mij.jar file defined in matlab's static javaclasspath.txt by this way:
function Miji
...
MIJ.start(); % the mij.jar defines a MIJ static object and can be directly loaded
...
end
In a matlab session, a MIJ can be created only once in the first time by either by calling
MIJ % creat a MIJ object
ans =
MIJ@73862f81
or by calling
MIJ.start() % this not only create MIJ, but also initialize a GUI window
or by calling
Miji(); % this not only create MIJ, but also initialize a GUI window
===========
Now I have a function that use MIJ object as argument. To make a test in case of no argument, usually I wrote a ~nargin block in the beginning.
function dosomething(MIJ,......)
if ~nargin
Miji(); % call MIJI() to establish MIJ in the first time
arg2 = 1;
arg3 = 22;
%...
end
MIJ.run('some command')
end
If I run it without argument , the error is :
Not enough input arguments.
Error in dosomething (line 12)
MIJ.run('Close All');
However, if I delete the 1st argument, then it runs OK.
function dosomething(......)
if ~nargin
Miji(); % call MIJI() to establish MIJ in the first time
arg2 = 1;
arg3 = 22;
%...
end
MIJ.run('some command') % because MIJ was not decleared as input or variable, so it goes into the mij.jar to find the class MIJ
end
Also, if I call it with argument, it also runs OK.
Miji();
dosomething(MIJ,2,34,134)% use original version.
% In this scenario, MIJ was a static class that exist in memory, although MIJ is always not in the matlab variable list.
So the problem is that declare the MIJ as an argument of a function prevent its alternative as a static java class of the same name.
So to make the function runs without argument and without Miji() called beforehand in a new matlab session, how to modify the code to make it works?
0 个评论
回答(0 个)
另请参阅
类别
Robotics and Autonomous Systems
Simulink 3D Animation
Classic Virtual Reality World
Interact with Virtual Reality Worlds
在 Help Center 和 File Exchange 中查找有关 Interact with Virtual Reality Worlds 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!