- Notifications
You must be signed in to change notification settings - Fork 6
Maybe I'm missing something? Conversion issue #9
Description
Hey,
Please excuse me if this has a really easy solution but I'm farily new to matlab and coding in general.
So I've been using mlapp2classdef to convert a simple app I made in App Designer just to test if I can end up with a final standalone file that works. The sample is just an axes with a push button that plots cos(x) after it is pushed. After I run the conversion, mlapp2classdef([], 'ReplaceAppUI, true) I get an error saying:
While setting property 'UIAxes' of class 'testclick': Value must be 'matlab.ui.control.UIAxes'. Error in testclick/createComponents (line 39) app.UIAxes = axes(app.UIFigure); Error in testclick (line 79) createComponents(app)
My file name is "testclick". Here is the code that the conversion generates from my sample.
classdef testclick < matlab.apps.AppBase % Properties that correspond to app components properties (Access = public) UIFigure@matlab.ui.Figure UIAxes@matlab.ui.control.UIAxes Plot@matlab.ui.control.Button XEditFieldLabel@matlab.ui.control.Label XEditField@matlab.ui.control.NumericEditField YEditFieldLabel@matlab.ui.control.Label YEditField@matlab.ui.control.NumericEditField end methods (Access = private) % Button pushed function: Plot function PlotPushed(app, event) x=0:.01:100; y=cos(x); plot(app.UIAxes,x,y); app.XEditField.Value=10; app.YEditField.Value=100; end end % App initialization and construction methods (Access = private) % Create UIFigure and components function createComponents(app) % Create UIFigure app.UIFigure = figure; app.UIFigure.Position = [100 100 634 308]; app.UIFigure.Name = 'UI Figure'; setAutoResize(app, app.UIFigure, true) % Create UIAxes app.UIAxes = axes(app.UIFigure); title(app.UIAxes, 'Title'); xlabel(app.UIAxes, 'X'); ylabel(app.UIAxes, 'Y'); app.UIAxes.Position = [259 80 300 185]; % Create Plot app.Plot = uicontrol('Parent', app.UIFigure, 'push', 'Style', 'pushbutton'); app.Plot.ButtonPushedFcn = createCallbackFcn(app, @PlotPushed, true); app.Plot.Position = [96 216 100 22]; app.Plot.Text = 'Plot'; % Create XEditFieldLabel app.XEditFieldLabel = uicontrol('Parent', app.UIFigure, 'Style', 'text'); app.XEditFieldLabel.HorizontalAlignment = 'right'; app.XEditFieldLabel.Position = [56 165 25 15]; app.XEditFieldLabel.Text = 'X'; % Create XEditField app.XEditField = uicontrol('Parent', app.UIFigure, 'numeric', 'Style', 'edit'); app.XEditField.Position = [96 161 100 22]; % Create YEditFieldLabel app.YEditFieldLabel = uicontrol('Parent', app.UIFigure, 'Style', 'text'); app.YEditFieldLabel.HorizontalAlignment = 'right'; app.YEditFieldLabel.Position = [57 118 25 15]; app.YEditFieldLabel.Text = 'Y'; % Create YEditField app.YEditField = uicontrol('Parent', app.UIFigure, 'numeric', 'Style', 'edit'); app.YEditField.Position = [97 114 100 22]; end end methods (Access = public) % Construct app function app = testclick() % Create and configure components createComponents(app) % Register the app with App Designer % Function call removed 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 And lastly here is the code converted just with mlapp2classdef([])
classdef testclick < matlab.apps.AppBase % Properties that correspond to app components properties (Access = public) UIFigure matlab.ui.Figure UIAxes matlab.ui.control.UIAxes Plot matlab.ui.control.Button XEditFieldLabel matlab.ui.control.Label XEditField matlab.ui.control.NumericEditField YEditFieldLabel matlab.ui.control.Label YEditField matlab.ui.control.NumericEditField end methods (Access = private) % Button pushed function: Plot function PlotPushed(app, event) x=0:.01:100; y=cos(x); plot(app.UIAxes,x,y); app.XEditField.Value=10; app.YEditField.Value=100; end 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 634 308]; app.UIFigure.Name = 'UI Figure'; setAutoResize(app, app.UIFigure, true) % Create UIAxes app.UIAxes = uiaxes(app.UIFigure); title(app.UIAxes, 'Title'); xlabel(app.UIAxes, 'X'); ylabel(app.UIAxes, 'Y'); app.UIAxes.Position = [259 80 300 185]; % Create Plot app.Plot = uibutton(app.UIFigure, 'push'); app.Plot.ButtonPushedFcn = createCallbackFcn(app, @PlotPushed, true); app.Plot.Position = [96 216 100 22]; app.Plot.Text = 'Plot'; % Create XEditFieldLabel app.XEditFieldLabel = uilabel(app.UIFigure); app.XEditFieldLabel.HorizontalAlignment = 'right'; app.XEditFieldLabel.Position = [56 165 25 15]; app.XEditFieldLabel.Text = 'X'; % Create XEditField app.XEditField = uieditfield(app.UIFigure, 'numeric'); app.XEditField.Position = [96 161 100 22]; % Create YEditFieldLabel app.YEditFieldLabel = uilabel(app.UIFigure); app.YEditFieldLabel.HorizontalAlignment = 'right'; app.YEditFieldLabel.Position = [57 118 25 15]; app.YEditFieldLabel.Text = 'Y'; % Create YEditField app.YEditField = uieditfield(app.UIFigure, 'numeric'); app.YEditField.Position = [97 114 100 22]; end end methods (Access = public) % Construct app function app = testclick() % 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