views:

473

answers:

5

I have this patch code which i downloaded from a web article (Calling Matlab from Java). http://www.cs.virginia.edu/~whitehouse/matlab/JavaMatlab.html

But I donot know how to apply it in my windowsXp running computer. What I'm trying to do is call Matlab script file from java. I have found the necessary source codes and every thing but this mater is holding be back. Any help is highly appreciated. Thank you.

Here's the patch code.

Index: MatlabControl.java
===================================================================
RCS file: /cvsroot/tinyos/tinyos-1.x/tools/java/net/tinyos/matlab/MatlabControl.java,v
retrieving revision 1.3
diff -u -r1.3 MatlabControl.java
--- MatlabControl.java 31 Mar 2004 18:43:50 -0000 1.3
+++ MatlabControl.java 16 Aug 2004 20:36:51 -0000
@@ -214,7 +214,8 @@
          matlab.evalConsoleOutput(command);
          }else{
-               matlab.fevalConsoleOutput(command, args, 0, null);
+               //     matlab.fevalConsoleOutput(command, args, 0, null);
+               matlab.fevalConsoleOutput(command, args);
          }
      } catch (Exception e) {
          System.out.println(e.toString());
+3  A: 

You need to apply that patch to the file MatlabControl.java. On Unix, you have the standard patch program to do that, but that ofcourse isn't normally present on Windows.

But looking at the patch file, it's very small and you could easily do the change by hand. Look at the patch file: The lines with a - in the left column must be removed. The lines with a + must be added.

So you must look in MatlabControl.java and remove this line:

matlab.fevalConsoleOutput(command, args, 0, null);

And add these lines:

//     matlab.fevalConsoleOutput(command, args, 0, null);
matlab.fevalConsoleOutput(command, args);

In other words, it's a very small and simple change, you just have to remove the last two arguments to the method call to fevalConsoleOutput().

If you want the patch command (and lots of other Unix utilities) on Windows, you could download and install Cygwin.

Jesper
Thanks a lot.. guess I ll go for your second suggestion
Niroshan
+2  A: 

I'd download the standard UNIX patch tool and use:

patch -p0 <my_patch.diff
Lukáš Lalinský
You may want to explain the OP that `patch` should be run in the directory containing `MatlabControl.java`.
Stephan202
So what I have to do is copy the code in to a file named 'my_patch.diff' and save it in the folder that MatlabControl.java file is and run above command in console, right?
Niroshan
Yes, `cd C:\directory\which\contains\MatlabControl.java` and then `patch -p0 < my_patch.diff`. Make sure that `patch` is in your `$PATH` or specify its absolute path.
Stephan202
+1  A: 

This patch is so small, you can easily apply it by hand.

So simply open the file MatlabControl.java and change line 214 (the one prepended with -) to fit the lines prepended with +.

After that your code should look like:

    else{
//                    matlab.fevalConsoleOutput(command, args, 0, null);
        matlab.fevalConsoleOutput(command, args);
    }
tangens
Thanks you so much this was very helpful
Niroshan
A: 

JMI (Java-to-Matlab Interface)'s Matlab class and its fevalConsoleOutput method are explained here: http://UndocumentedMatlab.com/blog/jmi-java-to-matlab-interface/

Yair Altman
A: 

If you use dev tools like Eclipse you can easily apply it as it is an option in the contextual menu (right click) as 'Apply Patch'. At least for me.

Kevin