我正在尝试通过将一些初始化分离到单独的 .m 文件中来整理我的 MATLAB 应用程序代码。为此,我为每种类型的组件设置了各种文件(例如按钮、图形等的文件)。我正尝试从按钮文件访问主初始化文件中的函数。我的代码在按钮 .m 文件中如下所示:
classdef buttons < handle
methods
%initializes the UI
function buttonCreate(app)
%Create file load 1
app.fileload1 = uibutton(app.gridLayout, 'push');
app.fileload1.FontSize = 36;
app.fileload1.Layout.Row = [8 9];
app.fileload1.Layout.Column = 1;
app.fileload1.Text = 'Load 1';
%proceeds to create the rest of the buttons
end
end
end
现在我尝试访问buttonCreate()
主初始化文件中的函数initialize.m
:
classdef initialize < handle
properties
fig
gridLayout
axes
fileload1
end
methods
%initializes the UI
function init(app)
%create canvas
import buttons.*;
fig = uifigure;
fig.Position = [100 100 1920 1080];
movegui(fig,'center');
fig.Name = "Audio Editor";
%Create grid layout
gridLayout = uigridlayout(fig);
gridLayout.ColumnWidth = {'1x', '1x', '1x', '1x', '1x', '1x', '1x', '1x', '1x', '1x'};
gridLayout.RowHeight = {'1x', '1x', '1x', '1x', '1x', '1x', '1x', '1x', '1x', '1x', '1x', '1x', '1x', '1x', '1x', '1x', '1x', '1x', '1x', '1x', '1x'};
buttonCreate(app);
end
end
%code for calling and deleting
methods
%calls code to create canvas upon app start
function app = initialize
init(app)
end
%removes the app and deletes app.fig
function delete(app)
delete(app.fig);
end
end
end
Error in initialize/init (line 41)
buttonCreate(app);
^^^^^^^^^^^^^^^^^^
Error in initialize (line 54)
init(app)
^^^^^^^^^
这导致程序UIFigure
仍在创建,但没有按钮,并且终端出现上述错误。
好像你正在做两件不同的事情的某种组合: