3

Let me explain what I am trying to do. I have an application coded in Matlab and I would like to provide it to both Matlab users and non-Matlab users. So you would say : Just compiled it and deploy an executable. Fine.

But deployed application are somehow limited in what you can do (very importantly, you can't execute other M-file) so I would like to ALSO make it possible to Matlab users to start the deployed application from Within Matlab and provide these advanced capabilities for these guys. So Is it possible?

Of course, I could provide two versions : A .exe and .m but this is not really elegant and maybe there is a nice trick to do this. Any idea?

dsolimano
  • 8,870
  • 3
  • 48
  • 63
  • I can't understand something: what is your app intended to do? i mean if it is trying to do something which can't be deployed to .exe files then practically you have to really have two different apps (not just versions). could you provide an example of what you are really asking for. – eulerleibniz Jun 16 '16 at 11:16

2 Answers2

1

You can use eval in deployed applications. You can also read .m files, since they are nothing but text. So, read the file, evaluate line by line, and there you go, you have an ability to use 3d party script .m files in your compiled Matlab program.

You will not be able to use functions in this way, only scripts.

The only thing I am not sure is whether it's legal. I can't guarantee that, you will have to contact Mathworks by yourself.

Andrey Rubshtein
  • 20,795
  • 11
  • 69
  • 104
  • I am not sure you can do this. See Loren blog : http://blogs.mathworks.com/loren/2008/06/19/writing-deployable-code/#11 – Jerome Lecoq May 13 '12 at 02:42
  • @Andrey - This would work for matlab scripts but Matlab functions? You couldn't evaluate them line-by-line because they need to be defined before you can call them. It may be possible to get this to work but you would need alot of code. Wouldn't you need to write your own Matlab parser to make this work? – grantnz May 13 '12 at 11:06
  • Evaluating line by line is really not going to be efficient and it does not look elegant either. This is basically reprogramming a matlab interpreter, bypassing the JIT and so on. Matlab is much faster at running functions files than script files due to this. I would really not like to dive into this. – Jerome Lecoq May 13 '12 at 20:42
  • @JeromeLecoq, can you explain your ultimate goal? Perhaps I can give you another solution. – Andrey Rubshtein May 13 '12 at 22:17
  • Thank you very much for your help. I made an application in Matlab that has a plugin system. You can put new piece of M-Code in a folder and the application will be able to pick it up as long as you respect a simple syntax. It works nice and easy in Matlab but is difficult to deploy without making the plugin very counterintuitive, so far. – Jerome Lecoq May 13 '12 at 22:52
0

Matlab doesn't have inbuilt functionality to do this, and, detecting whether someone has Matlab installed or not varies greatly depending on operating system.

Dhaivat Pandya
  • 6,499
  • 4
  • 29
  • 43
  • What about having an executable that called built in libraries and having an M file that call the same libraries? The user would either launch the M or the executable depending on his needs. – Jerome Lecoq May 12 '12 at 22:34