Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8165015
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T19:26:31+00:00 2026-06-06T19:26:31+00:00

I used MatlabConrol to connect Java and MATLAB. I want to send an image

  • 0

I used MatlabConrol to connect Java and MATLAB. I want to send an image path to MATLAB to process it with matching functions and give me back a number of similar images and paths, to show in the Java GUI.

I always get the same error when passing an image path to MATLAB:

Error using eval
Undefined function 'getinput' for input arguments of type 'char'.

Here’s my MATLAB function:

function matlab = getinput(input)
results = hgr(input);

And my Java code:

imag = ImageIO.read(fileChoose.getSelectedFile());
ImagePath = fileChoose.getSelectedFile().getAbsolutePath();

public void SendingMatlabControl() throws MatlabConnectionException,
  MatlabInvocationException {
  // create proxy
  MatlabProxy proxy;
  // Create a proxy, which we will use to control MATLAB
  MatlabProxyFactory factory = new MatlabProxyFactory();
  proxy = factory.getProxy();
  // Display 'hello world' like before, but this time using feval
    try {
      // call builtin function
      proxy.eval("getinput('imagepath')");
      // call user-defined function (must be on the path)
      proxy.eval("addpath('E:\\vm')");
      proxy.feval("matlab");
      proxy.eval("rmpath('E:\\vm)");
    } catch (MatlabInvocationException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    // Disconnect the proxy from MatLab
    proxy.disconnect();
  }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T19:26:33+00:00Added an answer on June 6, 2026 at 7:26 pm

    Let me give an example of calling a function, passing it input, and retrieving the output. There are two ways, either:

    • use eval and assign the result of the function inside the MATLAB workspace, then retrieve those variables using getVariable, or
    • use returningFeval to evaluate the function with its inputs, and directly retrieve the output.

    Suppose we had a MATLAB function myfunc.m that takes a string as input, and returns a cell array containing a string, a number, and a vector:

    function out = myfunc(str)
        out = cell(3,1);
        out{1} = sprintf('Welcome to %s!', str);
        out{2} = 99;
        out{3} = rand(10,1);
    end
    

    Here is the Java code:

    import matlabcontrol.*;
    
    public class TestMyFunc
    {
        public static void main(String[] args)
            throws MatlabConnectionException, MatlabInvocationException
        {
            // create proxy
             MatlabProxyFactoryOptions options =
                new MatlabProxyFactoryOptions.Builder()
                    .setUsePreviouslyControlledSession(true).build();
            MatlabProxyFactory factory = new MatlabProxyFactory(options);
            MatlabProxy proxy = factory.getProxy();
    
            // call function and get output cell array
            String in = "Stack Overflow";
            Object[] out = proxy.returningFeval("myfunc", 1, in);
    
            // extract stuff from cell array
            out = (Object[]) out[0];
            String str = (String) out[0];
            double x = ((double[]) out[1])[0];
            double[] arr = (double[]) out[2];
    
            // show result
            System.out.println("str =\n " + str);
            System.out.println("x = \n " + x);
            System.out.println("arr =");
            for(int i=0; i < arr.length; i++) {
                System.out.println(" " + arr[i]);
            }
    
            // shutdown MATLAB
            //proxy.feval("quit");
    
            // close connection
            proxy.disconnect();
        }
    }
    

    I get the output:

    str =
     Welcome to Stack Overflow!
    x =
     99.0
    arr =
     0.5974901918725793
     0.3353113307052461
     0.29922502333310663
     0.45259254156932405
     0.42264565322046244
     0.35960631797223563
     0.5583191998692971
     0.7425453657019391
     0.42433478362569066
     0.42935578857620504
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I used the phonegap website to create an IPA file. Now I want to
I used a motion tracker in After effects to trace the path of an
Used XStream lib, but no children XML was difficult to parse in Java. Wanting
I used Lazy Loader to load image in my listView and the image is
Never used a cache like this before. The problem is that I want to
used image as like map , user can zoom in/out this image.geting x and
I used the following code to load the xml for further process, while load
Used this command to start the web app using jetty-runner java -jar prject123/web/target/dependency/jetty-runner.jar project123/web/target/*.war
I used to build a website on ASP.NET MVC. Now I want to build
I used a 3rdparty image merging watermarking script to watermark some images, though it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.