Matlab connection to Vaadin GUI

Hi,

I have data in matlab that is simulated to produce some results into some matlab files. I would love to develop a Vaadin interface that would show these matlab files for the user to see these files in the Vaadin interface. I suppose there would be a Vaadin addon which can connect matlab to the Vaadin interface to make this work. Please help me out with how to achieve this. Many Thanks.

So you are not developing a Matlab editor, but just a way to display the data files?

For textual display with variable-height lines, I’d probably suggest using Label components in a VerticalLayout. To enable scrolling, you could put that in a Panel.

To display tabular data, you can use Table. However, a Table does not handle variable-height lines properly.

You could also use the
MathQuill
add-on to display some kinds of data in mathematical format.

There’s no Matlab-related add-ons for Vaadin. Handling the Matlab file reading and such are not related to user interfaces.

Hello Marko,

Thanks for your response. I am currently running commands in matlab to simulate data and the results is saved in matlab files. The idea is to make life easier for the user of the Vaadin interface to run the commands from the vaadin interface, perhaps with the click of a button. That means when the button is clicked, the vaadin interface should connect to the method that simulates the data in matlab and then display the results on the vaadin interface, perhaps in a tabular format as you have suggested. There is a suggestion in another forum, the link is below which seems to be familiar with what i want to do.

http://stackoverflow.com/questions/23221632/using-libraries-in-vaadin-com-vaadin-server-serviceexception

However, i cannot find the jar file " matlabcontrol" or “MatlabProxyFactory” which is being suggested there. I hope you get the clear picture of what i want to do now. Thanks

Hi, the matlabcontol library seems to be available from
here
. It really has nothing to do with Vaadin - it’s just a business logic library for Java. You just need to design the Vaadin user interface to utilize it in the way that you want.

The library seems to be distributed only as a JAR, so you can’t use a Maven or Ivy dependency to get it, but you need to download and install it in the WEB-INF/lib directory (under WebContent in Eclipse projects).

Thanks Marko. I have the matlabcontrol-demo-4.1.0 jar in the WEB-INF/lib directory as you stated and also in the buildpath as well. I run the following code to test as a java application in a vaadin project:

public static void main(String args) throws MatlabConnectionException, MatlabInvocationException
{
//Create a proxy, which we will use to control MATLAB
MatlabProxyFactory factory = new MatlabProxyFactory();
MatlabProxy proxy = factory.getProxy();

    //Display 'hello world' just like when using the demo
    proxy.eval("disp('hello world')");

    //Disconnect the proxy from MATLAB
    proxy.disconnect();
}

However, i receive an exception which indicates that my matlab is not in a known location. I have produced the exception as below: is there any specific way to configure matlab to fix this problem? Many thanks.

Exception in thread “main” matlabcontrol.MatlabConnectionException: Could not launch MATLAB. This is likely caused by MATLAB not being in a known location or on a known path. MATLAB’s location can be explicitly provided by using matlabcontrol.MatlabProxyFactoryOptions.Builder’s setMatlabLocation(…) method.
OS: Windows 7
Command: [matlab, -r, javaaddpath ‘C:\Users\a\workspace\utadisint\WebContent\WEB-INF\lib\matlabcontrol-4.1.0.jar’; matlabcontrol.MatlabClassLoaderHelper.configureClassLoading(); javarmpath ‘C:\Users\a\workspace\utadisint\WebContent\WEB-INF\lib\matlabcontrol-4.1.0.jar’; matlabcontrol.MatlabConnector.connectFromMatlab(‘PROXY_RECEIVER_3be81980-3680-4cb6-91b3-e365a930d2e8’, 2100);]

Environment: {ProgramData=C:\ProgramData, GECODEDIR=C:\Program Files (x86)\Gecode, TERM=dumb, USERPROFILE=C:\Users\a, PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC, ProgramFiles(x86)=C:\Program Files (x86), SystemDrive=C:, TEMP=C:\Users\a\AppData\Local\Temp, ProgramFiles=C:\Program Files, Path=C:/Program Files/Java/jre6/bin/server;C:/Program Files/Java/jre6/bin;C:/Program Files/Java/jre6/lib/amd64;C:\Program Files\Java\jre6\bin;C:\strawberry\c\bin;C:\strawberry\perl\site\bin;C:\strawberry\perl\bin;c:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn;c:\Program Files\Microsoft SQL Server\100\Tools\Binn;c:\Program Files\Microsoft SQL Server\100\DTS\Binn;C:\Program Files (x86)\Windows Kits\8.1\Windows Performance Toolkit;C:\Program Files\Microsoft SQL Server\110\Tools\Binn;C:\Program Files (x86)\Gecode\bin;C:\Program Files\Java\jre6\bin;C:\Users\a\Downloads\eclipse-jee-indigo-SR2-win32-x86_64\eclipse;, HOMEDRIVE=C:, PROCESSOR_REVISION=2a07, USERDOMAIN=B870, ALLUSERSPROFILE=C:\ProgramData, ProgramW6432=C:\Program Files, PROCESSOR_IDENTIFIER=Intel64 Family 6 Model 42 Stepping 7, GenuineIntel, SESSIONNAME=Console, TMP=C:\Users\a\AppData\Local\Temp, PROCESSOR_ARCHITECTURE=AMD64, LOGONSERVER=\B870, =::=::, CommonProgramFiles=C:\Program Files\Common Files, OS=Windows_NT, FP_NO_HOST_CHECK=NO, HOMEPATH=\Users\a, PROCESSOR_LEVEL=6, CommonProgramW6432=C:\Program Files\Common Files, LOCALAPPDATA=C:\Users\a\AppData\Local, VS120COMNTOOLS=C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\Tools, COMPUTERNAME=B870, SystemRoot=C:\Windows, windir=C:\Windows, NUMBER_OF_PROCESSORS=4, PSModulePath=C:\Windows\system32\WindowsPowerShell\v1.0\Modules, PUBLIC=C:\Users\Public, USERNAME=a, CommonProgramFiles(x86)=C:\Program Files (x86)\Common Files, ComSpec=C:\Windows\system32\cmd.exe, APPDATA=C:\Users\a\AppData\Roaming}
at matlabcontrol.RemoteMatlabProxyFactory.createProcess(RemoteMatlabProxyFactory.java:323)
at matlabcontrol.RemoteMatlabProxyFactory.requestProxy(RemoteMatlabProxyFactory.java:125)
at matlabcontrol.RemoteMatlabProxyFactory.getProxy(RemoteMatlabProxyFactory.java:144)
at matlabcontrol.MatlabProxyFactory.getProxy(MatlabProxyFactory.java:81)
at com.example.utadisint.matlabtest.main(matlabtest.java:16)
Caused by: java.io.IOException: Cannot run program “matlab”: CreateProcess error=2, Det går inte att hitta filen
at java.lang.ProcessBuilder.start(Unknown Source)
at matlabcontrol.RemoteMatlabProxyFactory.createProcess(RemoteMatlabProxyFactory.java:303)
… 4 more
Caused by: java.io.IOException: CreateProcess error=2, Det går inte att hitta filen
at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl.(Unknown Source)
at java.lang.ProcessImpl.start(Unknown Source)
… 6 more

You should probably ask those questions from the matlabcontrol developers, they are in no way related to Vaadin.

Thanks Marko for the help. I would post this for others who may be interested in how to get matlab to work in vaadin. it works for me now :slight_smile:

public class matlabtest {
static MatlabProxyFactory factory;
static MatlabProxy proxy;
public static MatlabProxyFactoryOptions builder;

public static void main(String[] args) throws MatlabConnectionException, MatlabInvocationException
{
    \\remember to set the path to the matlab executable on your  computer in the       \\MatlabProxyFactoryOptions.Builder().setMatlabLocation as below, it is very important

    builder = new MatlabProxyFactoryOptions.Builder().setMatlabLocation("C:\\Program Files\\MATLAB\\R2012b\\bin\\matlab.exe").setUsePreviouslyControlledSession(true).setHidden(false).build();
    factory = new MatlabProxyFactory(builder);
     proxy = factory.getProxy();
     proxy.eval("disp('hello world')");
     proxy.disconnect();

}

Hello Marko,
I extracted a 2 * 1 array data from a matlab data variable . The data is contained in variable J as below:
MLArray j = matfilereader.getMLArray(“marginal_utils”);

I am trying to display this data array contained in J in a vaadin table as follows:

Table thresholdstable = new Table();
// Create a container for table thresholdsdata
Container thresholdstablecontainer = new IndexedContainer();
thresholdstablecontainer.addContainerProperty(j, Double.class, 0.0);

            thresholdstable.setContainerDataSource(thresholdstablecontainer);

However, the table is not able to display the data, it is empty. am i doing something wrong? Thanks

Read the
javadoc for IndexedContainer
, the
Book of Vaadin
or any of many other examples on how to use IndexedContainer either directly or via the Table API. Your


addContainerProperty()


call doesn’t make sense - the first parameter should be the item id, and the data you should insert as separate items.[color=#464440]
[font=Helvetica Neue, sans-serif]
[size=3]

[/size]
[/font]
[/color]

Hello Henri,

I have a situation whereby the array retrieved from matlab already contains the data. So i do not have the opportunity to insert the data as separate items. Is there any container that i can use to upload the whole array data into a table? I have tried CollectionContainer, LazyContainer and ArrayContainer, but i receive an error, because of the need to convert the matlab datatype MLDouble to a java object data type. Thanks

You either have to convert your MLArray somehow into an ArrayList, List, … (a class extending Collection.class in some way) so that you can then use it inside the constructor of IndexedContainer.

Another way would be to iterate over your MLArray and then add every row seperately to the Container/Table.

Btw. I have no experience in Matlab whatsoever so i can’t tell you how to exactly convert your array.