Implicit java object variable initializaton or declare

1 visualización (últimos 30 días)
raym
raym el 20 de Mzo. de 2019
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?

Respuestas (0)

Categorías

Más información sobre 3-D Volumetric Image Processing en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by