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!