MATLAB Compiler for a .mlapp that have a .m file

24 ビュー (過去 30 日間)
Eric Aw
Eric Aw 2021 年 10 月 14 日
コメント済み: Eric Aw 2021 年 10 月 16 日
I have tried a lot of times and tried searching for soemthing similar but couldn't find it
I have a .m file. Then I use app designer to create a GUI (.mlapp) that execute/run the .m file . It works perfectly in app designer where I click the run button and it will run the .m file ( this main .m file consists a lot of functions) .
However, when I try to use compiler to compile it to a standalone desktop app, and run it. It does have the GUI interface but it doesn't run my .m file.
I can't seem to understand why
If I just compile the .m file , it works perfectly too. It just doens't have the GUI interface that I desgined using app designer.
Can someone please give me some guidance ?
Below is my script:
I just need it to execute the run
classdef Lector6xx_Final_Testing < matlab.apps.AppBase
% Properties that correspond to app components
properties (Access = public)
UIFigure matlab.ui.Figure
ResultTextArea matlab.ui.control.TextArea
ResultTextAreaLabel matlab.ui.control.Label
Image matlab.ui.control.Image
filetypeTextArea matlab.ui.control.TextArea
filetypeTextAreaLabel matlab.ui.control.Label
TitleEditField matlab.ui.control.EditField
TitleLabel matlab.ui.control.Label
imageVariantTextArea matlab.ui.control.TextArea
imageVariantTextAreaLabel matlab.ui.control.Label
focusTextArea matlab.ui.control.TextArea
focusTextAreaLabel matlab.ui.control.Label
InputoftestcaseTextArea matlab.ui.control.TextArea
InputoftestcaseTextAreaLabel matlab.ui.control.Label
StartButton matlab.ui.control.Button
end
% Callbacks that handle component events
methods (Access = private)
% Button pushed function: StartButton
function StartButtonPushed(app, event)
run("C:\Users\a\Documents\MATLAB\Test_main_Edited.m")
end
end
% Component initialization
methods (Access = private)
% Create UIFigure and components
function createComponents(app)
% Create UIFigure and hide until all components are created
app.UIFigure = uifigure('Visible', 'off');
app.UIFigure.Color = [0.9412 0.9412 0.9412];
app.UIFigure.Position = [100 100 640 480];
app.UIFigure.Name = 'MATLAB App';
% Create StartButton
app.StartButton = uibutton(app.UIFigure, 'push');
app.StartButton.ButtonPushedFcn = createCallbackFcn(app, @StartButtonPushed, true);
app.StartButton.BackgroundColor = [0.7098 0.9686 0.9647];
app.StartButton.Position = [481 118 100 22];
app.StartButton.Text = 'Start';
% Create InputoftestcaseTextAreaLabel
app.InputoftestcaseTextAreaLabel = uilabel(app.UIFigure);
app.InputoftestcaseTextAreaLabel.HorizontalAlignment = 'right';
app.InputoftestcaseTextAreaLabel.Position = [14 218 94 22];
app.InputoftestcaseTextAreaLabel.Text = 'Input of testcase';
% Create InputoftestcaseTextArea
app.InputoftestcaseTextArea = uitextarea(app.UIFigure);
app.InputoftestcaseTextArea.Position = [123 177 266 65];
app.InputoftestcaseTextArea.Value = {'contrast-csv, spatialdefects, singlePixelSaturation'};
% Create focusTextAreaLabel
app.focusTextAreaLabel = uilabel(app.UIFigure);
app.focusTextAreaLabel.HorizontalAlignment = 'right';
app.focusTextAreaLabel.Position = [14 139 38 22];
app.focusTextAreaLabel.Text = 'focus ';
% Create focusTextArea
app.focusTextArea = uitextarea(app.UIFigure);
app.focusTextArea.Position = [123 137 266 26];
app.focusTextArea.Value = {'6 or 12 , mm'};
% Create imageVariantTextAreaLabel
app.imageVariantTextAreaLabel = uilabel(app.UIFigure);
app.imageVariantTextAreaLabel.HorizontalAlignment = 'right';
app.imageVariantTextAreaLabel.Position = [14 91 76 22];
app.imageVariantTextAreaLabel.Text = 'imageVariant';
% Create imageVariantTextArea
app.imageVariantTextArea = uitextarea(app.UIFigure);
app.imageVariantTextArea.Position = [123 72 266 43];
app.imageVariantTextArea.Value = {'1 or 2 '};
% Create TitleLabel
app.TitleLabel = uilabel(app.UIFigure);
app.TitleLabel.BackgroundColor = [0 0.4471 0.7412];
app.TitleLabel.HorizontalAlignment = 'center';
app.TitleLabel.FontSize = 18;
app.TitleLabel.FontColor = [1 1 1];
app.TitleLabel.Position = [190 436 49 27];
app.TitleLabel.Text = 'Title :';
% Create TitleEditField
app.TitleEditField = uieditfield(app.UIFigure, 'text');
app.TitleEditField.HorizontalAlignment = 'center';
app.TitleEditField.FontSize = 18;
app.TitleEditField.FontColor = [1 1 1];
app.TitleEditField.BackgroundColor = [0 0.4471 0.7412];
app.TitleEditField.Position = [246 436 236 27];
app.TitleEditField.Value = ' testing';
% Create filetypeTextAreaLabel
app.filetypeTextAreaLabel = uilabel(app.UIFigure);
app.filetypeTextAreaLabel.HorizontalAlignment = 'right';
app.filetypeTextAreaLabel.Position = [14 38 47 22];
app.filetypeTextAreaLabel.Text = 'file type';
% Create filetypeTextArea
app.filetypeTextArea = uitextarea(app.UIFigure);
app.filetypeTextArea.Position = [123 35 266 27];
app.filetypeTextArea.Value = {'.bmp or . jpg'};
% Create Image
app.Image = uiimage(app.UIFigure);
app.Image.Position = [254 260 164 158];
app.Image.ImageSource = 'le.PNG';
% Create ResultTextAreaLabel
app.ResultTextAreaLabel = uilabel(app.UIFigure);
app.ResultTextAreaLabel.BackgroundColor = [1 1 0.0667];
app.ResultTextAreaLabel.HorizontalAlignment = 'center';
app.ResultTextAreaLabel.Position = [432 62 40 22];
app.ResultTextAreaLabel.Text = 'Result';
% Create ResultTextArea
app.ResultTextArea = uitextarea(app.UIFigure);
app.ResultTextArea.BackgroundColor = [1 1 0.0667];
app.ResultTextArea.Position = [480 35 150 60];
app.ResultTextArea.Value = {'Result is automatically saved in a txt file in the same folder'};
% Show the figure after all components are created
app.UIFigure.Visible = 'on';
end
end
% App creation and deletion
methods (Access = public)
% Construct app
function app = Final_Testing
% Create UIFigure and 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
Thanks in advance

採用された回答

Walter Roberson
Walter Roberson 2021 年 10 月 15 日
編集済み: Walter Roberson 2021 年 10 月 15 日
Functions Not Supported for Compilation by MATLAB Compiler and MATLAB Compiler SDK
[...]
run
What you should do is invoke the code without using run . Make sure it is on your MATLAB path and call it by name.
  3 件のコメント
Walter Roberson
Walter Roberson 2021 年 10 月 15 日
run("C:\Users\a\Documents\MATLAB\Test_main_Edited.m")
In order to compile that, you would have to have added C:\Users\a\Documents\MATLAB to your MATLAB path (if it is not already there)
Then you would replace that call with
Test_main_Edited;
What the run() function does is locate the indicated file, cd() to the directory, and use evalin('caller') the name of the file (with extension removed.) . In the situation where the file is already on the path and the name is not overshadowed, then just naming the script has nearly the same effect. ("nearly" because if the script happens to refer to other functions or scripts in the same directory, then the fact that run() cd's to the directory can make a difference as to what gets invoked in the case where there is shadowing going on.)
Eric Aw
Eric Aw 2021 年 10 月 16 日
Understand. It works perfectly now .
Thank you very much for the guidance

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeInteractive Control and Callbacks についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by