1

I have tried to read many documentations (especially http://blogs.mathworks.com/loren/2008/08/11/path-management-in-deployed-applications/ where the question is asked but not answered to) on compiled Matlab GUI but was unable to find an answer to my question.

I want to create a compiled GUI in Matlab (compiled with deploytool and that can run on a computer that does not have Matlab), where at some point, the user can specify his own matlab .m file (say for example : myProfile.m) and the Gui uses it later on (this last point is the tricky part).

myProfile.m is some simple function (it takes one argument and outputs one value) that can be located wherever the user wants, and that is totally user defined. I give here a simple example:

function [y] = myProfile(x)
    y = x^2;
end

but it can be more complex.

In the Gui I ask the user the path to his profile function and I try to make it a function handle :

Button1 = uicontrol('String','Browse path to your Profile',...
        'Position',[320 10 150 150],...
        'Callback',@button1_Callback);
function [profileFunc] = button1_Callback(varargin)
      [ProfileName,ProfilePath] = uigetfile({'*.m'},'Select your profile'); 
      addpath(ProfilePath);
      profileFunc = str2func(strcat('@',ProfileName));
      % profileFunc will be used later on in the code
end

Of course, after compilation this code doesn't work, and I get the following error:

 'C:\Users\...\myProfile.m' is not in the application's expanded CTF archives at 
 'C:\Users\...\mcrCache8.0\myGui'. This is typically caused by calls to ADDPATH ...

I know that using addpath in a Gui does not work when you compile the Gui. But if I don't add the path, the program can not find the user provided myProfile.m . So how can I solve this?

Thanks,

Sam

SAM
  • 13
  • 3
  • 1
    Hi, I just found in an earlier blog (http://blogs.mathworks.com/loren/2008/06/19/writing-deployable-code/) "Compiled applications cannot read, parse, create or manipulate M-files at runtime". It is therefore the question if what you want is possible at all. – Nemesis Jan 19 '15 at 10:45
  • 2
    I agree, with @Nemesis. Even without your path problem, I don't think you can run a function which was not known at compile time. At least in sept 2011 [it wasn't yet possible](http://stackoverflow.com/questions/7409606/running-an-m-file-from-a-matlab-compiled-function/7409779#7409779). And if I quote the first paragraph of the link you mentioned "_a compiled application should not be able to change which functions it calls or the way those functions work_", or in the link from Nemesis: "_The MCR only executes encrypted M-files._" ... doesn't give you much hope. – Hoki Jan 19 '15 at 11:32
  • Duplicate of http://stackoverflow.com/questions/7409606/running-an-m-file-from-a-matlab-compiled-function – Sam Roberts Jan 19 '15 at 16:34
  • If profile function is simple enough, you may use `eval` on a user-provided string. `profile = 'sin(x^2)';` (or any other formula up to user convinience). Then in your code you can do `x= 10; y = eval(profile);` – CitizenInsane Jan 20 '15 at 15:59

1 Answers1

1

When viewing this from a licensing point it is very simple. Mathworks can not allow to deploy such code, you could easily deploy your own command line version of matlab which runs arbitriray code and does not require any license.

In my opinion there is only one way to go: Deploy m-code and ask the user to install matlab or octave.

Alternative: If you deploy a jar, the JRE is already running. Concider using java script as the JRE already brings the script engine. Then the user would have to input java script.

Daniel
  • 36,610
  • 3
  • 36
  • 69
  • 1
    Thanks! Considering that installing Matlab on other computers requires Licensing and deploying a Jar is more time consuming, I used an alternative. The user will now provide (via a simple gui interface) not a .m file but a .mat file with a structure array containing the 1 variable function. – SAM Jan 20 '15 at 10:37