【发布时间】:2015-03-17 07:41:57
【问题描述】:
我已尝试阅读有关已编译的 Matlab GUI 的许多文档(尤其是 http://blogs.mathworks.com/loren/2008/08/11/path-management-in-deployed-applications/,其中提出了问题但未回答),但无法找到我的问题的答案。
我想在 Matlab 中创建一个已编译的 GUI(使用 deploytool 编译,并且可以在没有 Matlab 的计算机上运行),在某些时候,用户可以指定他自己的 matlab .m 文件(例如: myProfile.m) 并且 Gui 稍后会使用它(最后一点是棘手的部分)。
myProfile.m 是一些简单的函数(它接受一个参数并输出一个值),它可以位于用户想要的任何位置,并且完全由用户定义。我这里举一个简单的例子:
function [y] = myProfile(x)
y = x^2;
end
但它可能更复杂。
在 Gui 中,我向用户询问其配置文件函数的路径,并尝试将其设为函数句柄:
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
当然,编译后这段代码不起作用,我得到以下错误:
'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 ...
我知道在编译 Gui 时在 Gui 中使用 addpath 不起作用。但是如果我不添加路径,程序将找不到用户提供的 myProfile.m 。那么我该如何解决呢?
谢谢,
山姆
【问题讨论】:
-
嗨,我刚刚在之前的博客 (blogs.mathworks.com/loren/2008/06/19/writing-deployable-code) 中发现“编译的应用程序无法在运行时读取、解析、创建或操作 M 文件”。因此,问题是你想要的东西是否可能。
-
我同意@Nemesis。即使没有您的路径问题,我认为您也无法运行编译时未知的函数。至少在 2011 年 9 月it wasn't yet possible。如果我引用您提到的链接的第一段“编译的应用程序不应更改它调用的函数或这些函数的工作方式”,或者来自 Nemesis 的链接:“MCR 只执行加密的 M 文件。" ... 不会给你太多希望。
-
如果配置文件功能足够简单,您可以在用户提供的字符串上使用
eval。profile = 'sin(x^2)';(或用户方便的任何其他公式)。然后在你的代码中你可以做x= 10; y = eval(profile);
标签: matlab user-interface compiler-errors