Hi every one,
hope u r fine.

i have a java program and it call matlab exe file ,but i have a problem in run time it is so so slow .

i need a help in how to make this faster, i will be grateful for any help

Hint:
"the matlab exe file take a url of an image from java code and then do some processing and finally return the result to the java program"

best wishes

Recommended Answers

All 20 Replies

i need a help in how to make this faster

You didn't post the code, so no idea how the program can be changed.
Are you sure it's not the matlab.exe program that is slow?

Have you tried the program with another .exe file to see what happens?
How fast does the matlab.exe program run by itself without the java program?

this is the code :

public int  testUrl(String url) {
		int  res = 0 ;
 		      try
 		      {
 		    	  //http://i2.ytimg.com/vi/yZScmrEnKlM/default.jpg
 		      Runtime rt = Runtime.getRuntime();
 		      String cmd = "testexebayes "+url;
 		      Process p = rt.exec(cmd);
 		      InputStream in = p.getInputStream();
 		      OutputStream out = p.getOutputStream();
 		      InputStream err = p.getErrorStream();
 		     BufferedReader output = new BufferedReader(new InputStreamReader(in));
 		    String nextLine = output.readLine();
 		   nextLine = output.readLine();
 		  nextLine = output.readLine();
 		  nextLine = output.readLine().trim();
 		    res = Integer.parseInt(nextLine);
 		 
 		      p.destroy() ;
		  
		      }catch(Exception exc){/*handle exception*/}
		      return res;
	}

the matlab exe file is not slow by it self i tested it before

thanx for your fast response

best wishes :)

Not sure what can be done to change how long this program takes to execute.

What do you see if you print out the values of nextLine as they are read.

it doesn't print any thing except the last nextLine it show me the result (0 or 1).

What do you see if you print out the values of nextLine as they are read.

Are the 4 lines that are read all blank?

yes except the last one it prints the result (0 or 1)

That's interesting. I wonder why the program prints 3 blank lines.
Does it do that if you execute it in a command prompt/terminal console?

It could also be your matlab file as well. What is the code in matlab?

when i run it form matlab console it doesn't slow but i think it run slow since i pass the url of the image and it open it from the url , is there another faster way to do that ??

thanx for your replies

when i run it form matlab console it doesn't slow

Is the command line you use from the console EXACTLY the same as the one you use in the java program?

it run slow since i pass the url of the image and it open it from the url

How is that different from the way you are using matlab from the console?

it is as the matlab console output ...


i think is the problem : read the image from the url >>>how can i solve it ??

Sorry, I can not understand what you are saying or asking.

How quickly does matlab respond when used manually in a console with a url?

it is slow also, and i think this is the problem not in the calling of matlab exe from java (how it will be solved ? )

problem not in the calling of matlab exe from java

Are you saying that matlab works with the same speed if used from a console compared to when used from a java program?

how it will be solved ?

I don't see where the problem is if it works with the same speed from console and from java program.

Please explain.

yes i found this after post the thread .
the problem nw how to speed the reading image from the url in matlab

thanx for all

So its not a Java programming problem.

Sorry, I know nothing about matlab.

yes it is not a java problem ,

vnm, i will try to fix it and i will ask some one to help me

best wishes

There is a dramatically easier way to call MATLAB from Java. You can use matlabcontrol available at http://matlabcontrol.googlecode.com which is a Java API that takes care of launching MATLAB (no need to mess with Runtime.exec(...) ) and then allows for continuous communication with MATLAB. Values from MATLAB get returned as real Java values, not string representations. There is even a class that automatically handles converting between MATLAB and Java numeric arrays. To get started take a look at the walkthrough available at http://code.google.com/p/matlabcontrol/wiki/Walkthrough

Note: I know this is an old post, but I wanted anyone who stumbles upon this thread from searching to know there is a much better way to interact with MATLAB from Java.

ashish: don't hijack dead threads.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.