最近小弟想用java调用matlab, 环境配置成功了, 但是当我想调用matlab通过java build形成的java类是却出现了问题。
首先我在matlab里写了.m函数文件, 该函数需要输入4个参数, 都是浮点型, 之后形成java包之后, 在形成的java文件中却只看到含有两个传递参数的java类。然后再在命令行执行java程序时, 提示错误:
... undefined 'dis_fd_depth' for input arguments of typt 'double'
希望得到各位前辈的指点!!!
谢谢!!
下面是matlab形成的java类:
/*
* MATLAB Compiler: 4.8 (R2008a)
* Date: Sun Jul 26 15:17:18 2009
* Arguments: "-B" "macro_default" "-W" "java:dis_fd_depth,dis_fd_depthclass"
* "-d" "C:\\Documents and Settings\\Administrator\\My
* Documents\\MATLAB\\dis_fd_depth\\src" "-T" "link:lib" "-v"
* "class{dis_fd_depthclass:C:\\Documents and
* Settings\\Administrator\\桌面\\dis_fd_depth.m}" 
*/package dis_fd_depth;import com.mathworks.toolbox.javabuilder.*;
import com.mathworks.toolbox.javabuilder.internal.*;
import java.util.*;/**
 * The <code>dis_fd_depthclass</code class provides a Java interface to the
 * M-functions from the files:
 * <pre>
 * C:\Documents and Settings\Administrator\桌面\dis_fd_depth.m
 * </pre>
 * The {@link #dispose} method <b>must</b> be called on a
 * <code>dis_fd_depthclass</code> instance when it is no longer needed to
 * ensure that native resources allocated by this class are properly freed.
 * @version 0.0
 */
public class dis_fd_depthclass extends MWComponentInstance<dis_fd_depthclass>
{
  /**
   * Tracks all instances of this class to ensure their dispose method is
   * called on shutdown.
   */
  private static Set<Disposable> sInstances = new HashSet<Disposable>();
  /**
   * Maintains information used in calling the <code>dis_fd_depth</code>
   * M-function.
   */
  private static final MWFunctionSignature sdis_fd_depthSignature = new MWFunctionSignature(0, false, "dis_fd_depth", 5, false);
  /**
   * Constructs a new instance of the <code>dis_fd_depthclass</code> class.
   */
  public dis_fd_depthclass() throws MWException
  {
    super(dis_fd_depthMCRFactory.newInstance());
    // add this to sInstances
    synchronized(sInstances) {
      sInstances.add(this);
    }
  }
  private static MWComponentOptions getPathToComponentOptions(String path)
  {
    MWComponentOptions options = new MWComponentOptions(new MWCtfExtractLocation(path), new MWCtfDirectorySource(path));
    return options;
    
  }
  /**
   * Constructs a new instance of the <code>dis_fd_depthclass</code> class. Use
   * this constructor to specify a component directory other than the default
   * location.
   * @param pathToComponent Path to component directory.
   */
  public dis_fd_depthclass(String pathToComponent) throws MWException
  {
    super(dis_fd_depthMCRFactory.newInstance(getPathToComponentOptions(pathToComponent)));
    // add this to sInstances
    synchronized(sInstances){
      sInstances.add(this);
    }
  }
  /**
   * Constructs a new instance of the <code>dis_fd_depthclass</code> class. Use
   * this constructor to specify the options required to instantiate this
   * component.
   * The options will be specific to the instance of this component being
   * created.
   * @param componentOptions Options specific to the component.
   */
  public dis_fd_depthclass(MWComponentOptions componentOptions) throws MWException
  {
    super(dis_fd_depthMCRFactory.newInstance(componentOptions));
    // add this to sInstances
    synchronized(sInstances){
      sInstances.add(this);
      
    }
  }
  /** Frees native resources associated with this object */
  public void dispose()
  {
    super.dispose();
    synchronized(sInstances) {
      sInstances.remove(this);
    }
  }
  /**
   * Invokes the first m-function specified by MCC, with any arguments given on
   * the command line, and prints the result.
   */
  public static void main (String[] args)
  {
    try {
      MWMCR mcr = dis_fd_depthMCRFactory.newInstance();
      mcr.runMain( sdis_fd_depthSignature, args);
      mcr.dispose();
      
    } catch (Throwable t) {
      t.printStackTrace();
    }
  }
  /**
   * Install a shutdown hook to call disposeAllInstances.
   */
  static
  {
    Runtime.getRuntime().addShutdownHook(new Thread(){public void run(){dis_fd_depthclass.disposeAllInstances();}});
  }
  /**
   * Helper for disposeAllInstances.
   */
  private static dis_fd_depthclass popInstance()
  {
    dis_fd_depthclass o = null;
    synchronized(sInstances) {
      Iterator i = sInstances.iterator();
      if (i.hasNext()) {
        o = (dis_fd_depthclass) i.next();
        sInstances.remove(o);
      }
    }
    return o;
  }
  /**
   * Calls dispose method for each outstanding instance of this class.
   */
  public static void disposeAllInstances()
  {
    if(null == sInstances) {
      return;
    }
    synchronized(sInstances) {
      dis_fd_depthclass o = popInstance();
      while (o != null) {
        o.dispose();
        o = popInstance();
      }
    }
  }
  /**
   * Provides the mlx interface for calling the <code>dis_fd_depth</code>
   * M-function. 
   * @param lhs List in which to return outputs. Number of outputs (nargout) is
   * determined by allocated size of this List. Outputs are returned as
   * sub-classes of <code>com.mathworks.toolbox.javabuilder.MWArray</code>.
   * Each output array should be freed by calling its <code>dispose()</code>
   * method. 
   * @param rhs List containing inputs. Number of inputs (nargin) is determined
   * by the allocated size of this List. Input arguments may be passed as
   * sub-classes of <code>com.mathworks.toolbox.javabuilder.MWArray</code>, or
   * as arrays of any supported Java type. Arguments passed as Java types are
   * converted to MATLAB arrays according to default conversion rules. 
   * @throws MWException An error has occured during the function call. 
   */
  public void dis_fd_depth(List lhs, List rhs) throws MWException
  {
    fMCR.invoke(lhs, rhs, sdis_fd_depthSignature);
  }
  /**
   * Provides the mlx interface for calling the <code>dis_fd_depth</code>
   * M-function. 
   * @param lhs array in which to return outputs. Number of outputs (nargout)
   * is determined by allocated size of this array. Outputs are returned as
   * sub-classes of <code>com.mathworks.toolbox.javabuilder.MWArray</code>.
   * Each output array should be freed by calling its <code>dispose()</code>
   * method. 
   * @param rhs array containing inputs. Number of inputs (nargin) is
   * determined by the allocated size of this array. Input arguments may be
   * passed as sub-classes of
   * <code>com.mathworks.toolbox.javabuilder.MWArray</code>, or as arrays of
   * any supported Java type. Arguments passed as Java types are converted to
   * MATLAB arrays according to default conversion rules. 
   * @throws MWException An error has occured during the function call. 
   */
  public void dis_fd_depth(Object[] lhs, Object[] rhs) throws MWException
  {
    fMCR.invoke(Arrays.asList(lhs), Arrays.asList(rhs), sdis_fd_depthSignature);
  }
  /**
   * Provides the standard interface for calling the <code>dis_fd_depth</code>
   * M-function with 5 input arguments. 
   * Input arguments may be passed as sub-classes of
   * <code>com.mathworks.toolbox.javabuilder.MWArray</code>, or as arrays of
   * any supported Java type. Arguments passed as Java types are converted to
   * MATLAB arrays according to default conversion rules.
   * @param rhs The inputs to the M function.
   * @throws MWException An error has occured during the function call.
   */
  public Object[] dis_fd_depth(Object... rhs) throws MWException
  {
    Object[] lhs = new Object[0];
    fMCR.invoke(Arrays.asList(lhs), MWMCR.getRhsCompat(rhs, sdis_fd_depthSignature), sdis_fd_depthSignature);
    return lhs;
  }
}

解决方案 »

  1.   

    未定义' dis_fd_depth '为输入参数的double型。
    楼主不急慢慢找
      

  2.   

    请问在myeclipse中,java要调用matlab生成的jar包时,系统环境如何配置?详细说明一下,谢谢了!
      

  3.   

    我觉得,matlab帮助说得还是挺清楚的
      

  4.   

    在web中如何配置matlab环境,报错:java.lang.Exception: Failed to find the runtime libraries, required by MATLAB Builder JA, on system path
      

  5.   

    未定义' dis_fd_depth '为输入参数的double型。
    楼主不急慢慢找,这个只有你自己能帮上你。