简体   繁体   中英

Matlab 2012a, static method invocation, not recognizing class outside current folder

I have a class Ellipse (handle, inherits from other class), that has one static method called createFromGaussian . It is located in a remote folder, that I add to Matlab path. The thing is that, if I try to invoke the static function BEFORE creating any Ellipse object, it fails:

>> Ellipse.createFromGaussian(arg1,arg2)
Undefined variable "Ellipse" or class "Ellipse.createFromGaussian".

It works if I try any of the following things:

  • I change current directory to that in which Ellipse.m file is located
  • Working from a remote directory, I create an Ellipse object beforehand:

     >> Ellipse() [C=, axis=[0.0,0.0], angle=0.0] >> Ellipse.createFromGaussian([],2) 

Is this supposed to be this way? The error message sounds weird to me: of course it cannot find variable "Ellipse" or class "Ellipse.createFromGaussian"! It should find "Ellipse" class

So the Ellipse classdef file, and the function file, are in the same folder called @Ellipse , and the PARENT of the @Ellipse folder is on the path? That is what Matlab requires for it's system to work.

From the the ML help : "You must use an @-folder if you want to use more than one file for your class definition. Methods defined in separate files match the file name to the function name and must be declared in the classdef file."

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM