我在某个文件夹中有一个 MATLAB App App.mlapp~/myapp/
。它使用的功能和 GUI 中使用的一些图形在~/myapp/subfolder
. 为了正确运行App.mlapp,我必须每次~/myapp/subfolder
在启动应用程序之前手动添加到我的路径中。
如何自动添加子文件夹?
我试着把addpath(genpath(~/myapp/subfolder));
. StartupFcn
但是,正如StartupFcn
在组件创建后调用的那样,它已经需要一些图形~/myapp/subfolder
,这种方法不起作用。组件是使用自动创建的功能创建的createComponents
,无法使用 App Designer Editor 进行编辑。
excaza 要求的最小示例。要创建它,请打开 App 设计器,创建一个新应用程序,在设计视图中添加一个按钮,并使用 Button Properties -> Text & Icon -> More Properties -> Icon File在路径中指定一个图标。然后从路径中删除图标的目录并尝试运行该应用程序。
classdef app1 < matlab.apps.AppBase
% Properties that correspond to app components
properties (Access = public)
UIFigure matlab.ui.Figure
Button matlab.ui.control.Button
end
% App initialization and construction
methods (Access = private)
% Create UIFigure and components
function createComponents(app)
% Create UIFigure
app.UIFigure = uifigure;
app.UIFigure.Position = [100 100 640 480];
app.UIFigure.Name = 'UI Figure';
% Create Button
app.Button = uibutton(app.UIFigure, 'push');
app.Button.Icon = 'help_icon.png';
app.Button.Position = [230 321 100 22];
end
end
methods (Access = public)
% Construct app
function app = app1
% Create and configure components
createComponents(app)
% Register the app with App Designer
registerApp(app, app.UIFigure)
if nargout == 0
clear app
end
end
% Code that executes before app deletion
function delete(app)
% Delete UIFigure when app is deleted
delete(app.UIFigure)
end
end
end