<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	
	>
<channel>
	<title>
	Comments on: JMI &#8211; Java-to-Matlab Interface	</title>
	<atom:link href="https://undocumentedmatlab.com/articles/jmi-java-to-matlab-interface/feed" rel="self" type="application/rss+xml" />
	<link>https://undocumentedmatlab.com/articles/jmi-java-to-matlab-interface?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=jmi-java-to-matlab-interface</link>
	<description>Professional Matlab consulting, development and training</description>
	<lastBuildDate>Sat, 29 Apr 2023 20:45:21 +0000</lastBuildDate>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.7.2</generator>
	<item>
		<title>
		By: Yair Altman		</title>
		<link>https://undocumentedmatlab.com/articles/jmi-java-to-matlab-interface#comment-521362</link>

		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Sat, 29 Apr 2023 20:45:21 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=1279#comment-521362</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://undocumentedmatlab.com/articles/jmi-java-to-matlab-interface#comment-521354&quot;&gt;Francisco Campos&lt;/a&gt;.

@Francisco - this is one of those cases where you should ask MathWorks support. After all, you&#039;re trying to use a supported Matlab functionality when you encountered this limitation. Maybe MathWorks will be able to resolve your problem. Alternatively, you could post your query on &lt;a href=&quot;https://www.mathworks.com/matlabcentral/answers&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Matlab Answers&lt;/a&gt;. If you discover a workaround, please post it here in a follow-up comment.]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://undocumentedmatlab.com/articles/jmi-java-to-matlab-interface#comment-521354">Francisco Campos</a>.</p>
<p>@Francisco &#8211; this is one of those cases where you should ask MathWorks support. After all, you&#8217;re trying to use a supported Matlab functionality when you encountered this limitation. Maybe MathWorks will be able to resolve your problem. Alternatively, you could post your query on <a href="https://www.mathworks.com/matlabcentral/answers" target="_blank" rel="nofollow">Matlab Answers</a>. If you discover a workaround, please post it here in a follow-up comment.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Francisco Campos		</title>
		<link>https://undocumentedmatlab.com/articles/jmi-java-to-matlab-interface#comment-521354</link>

		<dc:creator><![CDATA[Francisco Campos]]></dc:creator>
		<pubDate>Sat, 29 Apr 2023 08:55:08 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=1279#comment-521354</guid>

					<description><![CDATA[Hello, thanks for all your work that has been immensely useful for those working in the Matlab environment.

I have been trying to replace matlabcontrol with the official java matlab engine but faced a problem. In my case I want to invoke a matlab function by a java class that is instantiated within matlab. However, when the class tries to access the matlab engine the following exception is thrown: &lt;code&gt;Initializing MATLAB Engine API from MATLAB is not supported.&lt;/code&gt;

Can you confirm that the supported Matlab java interface does not allow connecting to a Matlab session where the java class was launched? This would then be a case where unfortunately the official interface does not replace matlabcontrol... Many thanks!]]></description>
			<content:encoded><![CDATA[<p>Hello, thanks for all your work that has been immensely useful for those working in the Matlab environment.</p>
<p>I have been trying to replace matlabcontrol with the official java matlab engine but faced a problem. In my case I want to invoke a matlab function by a java class that is instantiated within matlab. However, when the class tries to access the matlab engine the following exception is thrown: <code>Initializing MATLAB Engine API from MATLAB is not supported.</code></p>
<p>Can you confirm that the supported Matlab java interface does not allow connecting to a Matlab session where the java class was launched? This would then be a case where unfortunately the official interface does not replace matlabcontrol&#8230; Many thanks!</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Peyman		</title>
		<link>https://undocumentedmatlab.com/articles/jmi-java-to-matlab-interface#comment-419511</link>

		<dc:creator><![CDATA[Peyman]]></dc:creator>
		<pubDate>Fri, 02 Mar 2018 10:13:35 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=1279#comment-419511</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://undocumentedmatlab.com/articles/jmi-java-to-matlab-interface#comment-419505&quot;&gt;Peyman&lt;/a&gt;.

Ok, I see. I could figure out that it was a &lt;code&gt;double[]&lt;/code&gt; by calling &lt;code&gt;obj.getClass().getSimpleName()&lt;/code&gt;.
Thank you very much Yair for these great posts and answering instantly!!]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://undocumentedmatlab.com/articles/jmi-java-to-matlab-interface#comment-419505">Peyman</a>.</p>
<p>Ok, I see. I could figure out that it was a <code>double[]</code> by calling <code>obj.getClass().getSimpleName()</code>.<br />
Thank you very much Yair for these great posts and answering instantly!!</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Yair Altman		</title>
		<link>https://undocumentedmatlab.com/articles/jmi-java-to-matlab-interface#comment-419507</link>

		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Fri, 02 Mar 2018 09:07:03 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=1279#comment-419507</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://undocumentedmatlab.com/articles/jmi-java-to-matlab-interface#comment-419505&quot;&gt;Peyman&lt;/a&gt;.

@Peyman - running a Java object that calls Matlab from within Matlab is an easy way to debug Java programs that will later be deployed outside Matlab.

&lt;code&gt;[D&lt;/code&gt; means a &lt;code&gt;Double&lt;/code&gt; array. See &lt;a href=&quot;https://docs.oracle.com/javase/tutorial/reflect/class/classNew.html&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;here&lt;/a&gt; and &lt;a href=&quot;https://docs.oracle.com/javase/7/docs/api/java/lang/Class.html#getName%28%29&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;here&lt;/a&gt;. To get a more human-readable string (&#039;double[]&#039; in your case), use &lt;code&gt;className = hObject.getClass.getCanonicalName()&lt;/code&gt;.]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://undocumentedmatlab.com/articles/jmi-java-to-matlab-interface#comment-419505">Peyman</a>.</p>
<p>@Peyman &#8211; running a Java object that calls Matlab from within Matlab is an easy way to debug Java programs that will later be deployed outside Matlab.</p>
<p><code>[D</code> means a <code>Double</code> array. See <a href="https://docs.oracle.com/javase/tutorial/reflect/class/classNew.html" target="_blank" rel="nofollow">here</a> and <a href="https://docs.oracle.com/javase/7/docs/api/java/lang/Class.html#getName%28%29" target="_blank" rel="nofollow">here</a>. To get a more human-readable string (&#8216;double[]&#8217; in your case), use <code>className = hObject.getClass.getCanonicalName()</code>.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Peyman		</title>
		<link>https://undocumentedmatlab.com/articles/jmi-java-to-matlab-interface#comment-419505</link>

		<dc:creator><![CDATA[Peyman]]></dc:creator>
		<pubDate>Fri, 02 Mar 2018 08:51:11 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=1279#comment-419505</guid>

					<description><![CDATA[Hi Yair

What is the point of invoking matlab functions by a java-matlab connector from inside the matlab console like in all of your examples????? From inside a java class - where this all actually would make a sense - not much works as described above. I can mtEval a script but when it comes to invoking a function with input and/or return arguments, the only thing which works half way is this:
&lt;pre lang=&quot;java&quot;&gt;
Matlab.mtEval(&quot;functionWithInputAndReturnValue(3, 5)&quot;, 1);
&lt;/pre&gt;

but it returns a java.lang.Object and when I call getClass on it, I receive [D No clue what it is and how to convert it into a nummerical value!?

Can you please help.

again this DOESN&#039;T even compile:
&lt;pre lang=&quot;java&quot;&gt;
Object isTrigger = new Object();
        int[] args = new int[2];
        args[0] = 3;
        args[1] = 5;
        try {
            isTrigger = Matlab.mtFeval(&quot;functionWithInputAndReturnValue&quot;, args, 1);
        } catch (Exception e) {
            e.printStackTrace();
        } 
&lt;/pre&gt;]]></description>
			<content:encoded><![CDATA[<p>Hi Yair</p>
<p>What is the point of invoking matlab functions by a java-matlab connector from inside the matlab console like in all of your examples????? From inside a java class &#8211; where this all actually would make a sense &#8211; not much works as described above. I can mtEval a script but when it comes to invoking a function with input and/or return arguments, the only thing which works half way is this:</p>
<pre lang="java">
Matlab.mtEval("functionWithInputAndReturnValue(3, 5)", 1);
</pre>
<p>but it returns a java.lang.Object and when I call getClass on it, I receive [D No clue what it is and how to convert it into a nummerical value!?</p>
<p>Can you please help.</p>
<p>again this DOESN&#8217;T even compile:</p>
<pre lang="java">
Object isTrigger = new Object();
        int[] args = new int[2];
        args[0] = 3;
        args[1] = 5;
        try {
            isTrigger = Matlab.mtFeval("functionWithInputAndReturnValue", args, 1);
        } catch (Exception e) {
            e.printStackTrace();
        } 
</pre>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Peyman		</title>
		<link>https://undocumentedmatlab.com/articles/jmi-java-to-matlab-interface#comment-419390</link>

		<dc:creator><![CDATA[Peyman]]></dc:creator>
		<pubDate>Tue, 27 Feb 2018 23:41:24 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=1279#comment-419390</guid>

					<description><![CDATA[Hi Yair
It&#039;s a very nice post. I was able to run a Matlab script from within a Java class with 
&lt;pre lang=&quot;java&quot;&gt;
import com.mathworks.jmi.*
...
Matlab.mtEval(&quot;someScript&quot;);
...
&lt;/pre&gt;
in the matlab console!

but I couldn&#039;t get it run a function with input and/or output arguments, actually it doesn&#039;t even compile because it either can&#039;t call the function with the argument list or it can&#039;t convert the return type (java.lang.Object) into the assignee (int) type - and won&#039;t cast to an explicit cast. As all of your example invocations of Matlab.mtEval and Matlab.mtFeval are obviously examples run on Matlab console and not on a JVM, I was wondering if this is possible at all!!?? 

I have matlab 7.6.0 (2008a) and jdk/jvm 1.6.0 (both Matlab and compiler)

thx

PS: the code snippet:

&lt;pre lang=&quot;java&quot;&gt;
import com.mathworks.jmi.*;
import java.util.LinkedList;

public class MatlabRunner implements Runnable{
    public LinkedList rrIntervals;
    
    public MatlabRunner(LinkedList list) {
        this.rrIntervals = list;
    }
    
    @Override
    public void run() {
        System.out.println(&quot;running the matlab runner...&quot;);
        long t0 = System.nanoTime();
        int isTrigger = 0;
        
        while(isTrigger == 0) {
            try {
                isTrigger = (int) Matlab.mtEval(&quot;waitTrigger(ioObj, address)&quot;, 1);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
      
        long t1 = System.nanoTime();
        long elapsedTime = (long) ((t1 - t0) / 1000);
        System.out.println(&quot;elapse time = &quot; + elapsedTime);
           
        this.rrIntervals.remove();
        this.rrIntervals.add(elapsedTime);
    }
}
&lt;/pre&gt;]]></description>
			<content:encoded><![CDATA[<p>Hi Yair<br />
It&#8217;s a very nice post. I was able to run a Matlab script from within a Java class with </p>
<pre lang="java">
import com.mathworks.jmi.*
...
Matlab.mtEval("someScript");
...
</pre>
<p>in the matlab console!</p>
<p>but I couldn&#8217;t get it run a function with input and/or output arguments, actually it doesn&#8217;t even compile because it either can&#8217;t call the function with the argument list or it can&#8217;t convert the return type (java.lang.Object) into the assignee (int) type &#8211; and won&#8217;t cast to an explicit cast. As all of your example invocations of Matlab.mtEval and Matlab.mtFeval are obviously examples run on Matlab console and not on a JVM, I was wondering if this is possible at all!!?? </p>
<p>I have matlab 7.6.0 (2008a) and jdk/jvm 1.6.0 (both Matlab and compiler)</p>
<p>thx</p>
<p>PS: the code snippet:</p>
<pre lang="java">
import com.mathworks.jmi.*;
import java.util.LinkedList;

public class MatlabRunner implements Runnable{
    public LinkedList rrIntervals;
    
    public MatlabRunner(LinkedList list) {
        this.rrIntervals = list;
    }
    
    @Override
    public void run() {
        System.out.println("running the matlab runner...");
        long t0 = System.nanoTime();
        int isTrigger = 0;
        
        while(isTrigger == 0) {
            try {
                isTrigger = (int) Matlab.mtEval("waitTrigger(ioObj, address)", 1);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
      
        long t1 = System.nanoTime();
        long elapsedTime = (long) ((t1 - t0) / 1000);
        System.out.println("elapse time = " + elapsedTime);
           
        this.rrIntervals.remove();
        this.rrIntervals.add(elapsedTime);
    }
}
</pre>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Yair Altman		</title>
		<link>https://undocumentedmatlab.com/articles/jmi-java-to-matlab-interface#comment-419184</link>

		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Sat, 17 Feb 2018 17:00:48 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=1279#comment-419184</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://undocumentedmatlab.com/articles/jmi-java-to-matlab-interface#comment-419146&quot;&gt;Andrew Janke&lt;/a&gt;.

@Andrew - I fixed the MatlabControl link to its new home on GitHub]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://undocumentedmatlab.com/articles/jmi-java-to-matlab-interface#comment-419146">Andrew Janke</a>.</p>
<p>@Andrew &#8211; I fixed the MatlabControl link to its new home on GitHub</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Andrew Janke		</title>
		<link>https://undocumentedmatlab.com/articles/jmi-java-to-matlab-interface#comment-419146</link>

		<dc:creator><![CDATA[Andrew Janke]]></dc:creator>
		<pubDate>Thu, 15 Feb 2018 18:03:50 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=1279#comment-419146</guid>

					<description><![CDATA[Very useful post! I&#039;ll be using this in one of my current projects.

BTW, it looks like the &quot;MatlabControl&quot; link in the fifth paragraph is broken. It&#039;s pointing to googlecode.com, which is defunct. Could you update the link to MatlabControl&#039;s current home?]]></description>
			<content:encoded><![CDATA[<p>Very useful post! I&#8217;ll be using this in one of my current projects.</p>
<p>BTW, it looks like the &#8220;MatlabControl&#8221; link in the fifth paragraph is broken. It&#8217;s pointing to googlecode.com, which is defunct. Could you update the link to MatlabControl&#8217;s current home?</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Yair Altman		</title>
		<link>https://undocumentedmatlab.com/articles/jmi-java-to-matlab-interface#comment-393461</link>

		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Wed, 16 Nov 2016 10:00:39 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=1279#comment-393461</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://undocumentedmatlab.com/articles/jmi-java-to-matlab-interface#comment-393459&quot;&gt;Sergio&lt;/a&gt;.

@Sergio - you only need R2016b if you want to use the new (documented) Matlab engine interface. 

If you have R2016a or earlier you can use the undocumented JMI interface, as explained in the post above (and its &lt;a href=&quot;http://undocumentedmatlab.com/blog/tag/jmi&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;followup posts&lt;/a&gt;).]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://undocumentedmatlab.com/articles/jmi-java-to-matlab-interface#comment-393459">Sergio</a>.</p>
<p>@Sergio &#8211; you only need R2016b if you want to use the new (documented) Matlab engine interface. </p>
<p>If you have R2016a or earlier you can use the undocumented JMI interface, as explained in the post above (and its <a href="http://undocumentedmatlab.com/blog/tag/jmi" target="_blank" rel="nofollow">followup posts</a>).</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Sergio		</title>
		<link>https://undocumentedmatlab.com/articles/jmi-java-to-matlab-interface#comment-393459</link>

		<dc:creator><![CDATA[Sergio]]></dc:creator>
		<pubDate>Wed, 16 Nov 2016 09:38:00 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=1279#comment-393459</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://undocumentedmatlab.com/articles/jmi-java-to-matlab-interface#comment-391185&quot;&gt;Yair Altman&lt;/a&gt;.

Hello,

In relation to your last answer, is it necessary to have R2016b installed? I have R2013b so I don&#039;t have that: matlabroot/extern/engines/java/jar/engine.jar

Is there any solution apart from installing R2016b?]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://undocumentedmatlab.com/articles/jmi-java-to-matlab-interface#comment-391185">Yair Altman</a>.</p>
<p>Hello,</p>
<p>In relation to your last answer, is it necessary to have R2016b installed? I have R2013b so I don&#8217;t have that: matlabroot/extern/engines/java/jar/engine.jar</p>
<p>Is there any solution apart from installing R2016b?</p>
]]></content:encoded>
		
			</item>
	</channel>
</rss>
