MATLAB App designer - Standalone - Uigetfile (m.file)

2 views (last 30 days)
I'm trying to create an app for non-matlab users to data process a specific equipment.
The script works in MATLAB App Designer but when creating a standalone it won't work.
I've tried to figure out the problem and it seems like the importing of the .m file is the problem.
I tried to copy the data and input it instead of loading it and it works.
What exactly am i doing wrong when importing the .m data file?
Thank you guys!
classdef App < matlab.apps.AppBase
% Properties that correspond to app components
properties (Access = public)
UIFigure matlab.ui.Figure
GridLayout matlab.ui.container.GridLayout
LeftPanel matlab.ui.container.Panel
TabGroup matlab.ui.container.TabGroup
InputsTab matlab.ui.container.Tab
OnButton matlab.ui.control.Button
OffButton matlab.ui.control.Button
OnButton_4 matlab.ui.control.Button
OffButton_4 matlab.ui.control.Button
OnButton_2 matlab.ui.control.Button
OffButton_2 matlab.ui.control.Button
Filename1mButton matlab.ui.control.Button
Filename2mButton matlab.ui.control.Button
RemovethefirstXnumberofdataLabel matlab.ui.control.Label
RemovethefirstXnumberofdataEditField matlab.ui.control.NumericEditField
RemovethelastXnumberofdataEditFieldLabel matlab.ui.control.Label
RemovethelastXnumberofdataEditField matlab.ui.control.NumericEditField
NumberofpeaksinIMAGXLabel matlab.ui.control.Label
NumberofpeaksinIMAGXEditField matlab.ui.control.NumericEditField
SmoothSignalEditFieldLabel matlab.ui.control.Label
SmoothSignalEditField matlab.ui.control.NumericEditField
Plotfilename1filename2ButtonGroup matlab.ui.container.ButtonGroup
xxButton matlab.ui.control.ToggleButton
xyButton matlab.ui.control.ToggleButton
yxButton matlab.ui.control.ToggleButton
yyButton matlab.ui.control.ToggleButton
DotsvalueSwitchLabel matlab.ui.control.Label
DotsvalueSwitch matlab.ui.control.Switch
Inputs2Tab matlab.ui.container.Tab
Legendforfilename1EditFieldLabel matlab.ui.control.Label
Legendforfilename1EditField matlab.ui.control.EditField
Legendforfilename2EditFieldLabel matlab.ui.control.Label
Legendforfilename2EditField matlab.ui.control.EditField
LabelxaxisEditFieldLabel matlab.ui.control.Label
LabelxaxisEditField matlab.ui.control.EditField
LabelyaxisEditFieldLabel matlab.ui.control.Label
LabelyaxisEditField matlab.ui.control.EditField
TitleEditFieldLabel matlab.ui.control.Label
TitleEditField matlab.ui.control.EditField
RunButton matlab.ui.control.Button
RightPanel matlab.ui.container.Panel
UIAxes matlab.ui.control.UIAxes
end
% Properties that correspond to apps with auto-reflow
properties (Access = private)
onePanelWidth = 576;
end
% Callbacks that handle component events
methods (Access = private)
% Value changed function:
% RemovethefirstXnumberofdataEditField
function RemovethefirstXnumberofdataEditFieldValueChanged(app, event)
value = app.RemovethefirstXnumberofdataEditField.Value ;
end
% Value changed function:
% RemovethelastXnumberofdataEditField
function RemovethelastXnumberofdataEditFieldValueChanged(app, event)
value = app.RemovethelastXnumberofdataEditField.Value ;
end
% Value changed function: NumberofpeaksinIMAGXEditField
function NumberofpeaksinIMAGXEditFieldValueChanged(app, event)
value = app.NumberofpeaksinIMAGXEditField.Value ;
end
% Value changed function: SmoothSignalEditField
function SmoothSignalEditFieldValueChanged(app, event)
value = app.SmoothSignalEditField.Value ;
end
% Value changed function: DotsvalueSwitch
function DotsvalueSwitchValueChanged(app, event)
value = app.DotsvalueSwitch.Value
end
% Callback function
function Plotfilename1filename2ButtonGroupSelectionChanged(app, event)
selectedButton = app.Plotfilename1filename2ButtonGroup.SelectedObject ;
end
% Button pushed function: Filename1mButton
function Filename1mButtonPushed(app, event)
[file1,path1] = uigetfile('*.m') %open a matlab file
global filename1_IMAG_REAL
filename1_IMAG_REAL=fullfile(path1,file1);
end
% Callback function: OnButton,
% Plotfilename1filename2ButtonGroup
function OnButtonPushed(app, event)
app.RemovethefirstXnumberofdataEditField.Visible = 'on';
end
% Button pushed function: OffButton_4
function OffButton_4Pushed(app, event)
app.SmoothSignalEditField.Visible = 'off';
end
% Button pushed function: OnButton_4
function OnButton_4Pushed(app, event)
app.SmoothSignalEditField.Visible = 'on';
end
% Button pushed function: OffButton
function OffButtonPushed(app, event)
app.RemovethefirstXnumberofdataEditField.Visible = 'off';
end
% Button pushed function: OffButton_2
function OffButton_2Pushed(app, event)
app.RemovethelastXnumberofdataEditField.Visible = 'off';
end
% Button pushed function: OnButton_2
function OnButton_2Pushed(app, event)
app.RemovethelastXnumberofdataEditField.Visible = 'on';
end
% Button pushed function: RunButton
function RunButtonPushed(app, event)
% Remove the first number of data
if strcmp(app.RemovethefirstXnumberofdataEditField.Visible, 'on')
Rmv_X_data = app.RemovethefirstXnumberofdataEditField.Value
elseif strcmp(app.RemovethefirstXnumberofdataEditField.Visible, 'off')
Rmv_X_data = 'off'
end
% Remove the last number of data
if strcmp(app.RemovethelastXnumberofdataEditField.Visible, 'on')
Rmv_to_data = app.RemovethelastXnumberofdataEditField.Value
elseif strcmp(app.RemovethelastXnumberofdataEditField.Visible, 'off')
Rmv_to_data = 'off'
end
% Find peaks
find_peaksx = app.NumberofpeaksinIMAGXEditField.Value
% Smooth signal
if strcmp(app.SmoothSignalEditField.Visible, 'on')
Smooth_signal = app.SmoothSignalEditField.Value
elseif strcmp(app.SmoothSignalEditField.Visible, 'off')
Smooth_signal = 'off'
end
% Dots on or off
if strcmp(app.DotsvalueSwitch.Value,'On')
dots_value = 'on'
elseif strcmp(app.DotsvalueSwitch.Value,'Off')
dots_value = 'off'
end
% Plot which graph
% switch app.Plotfilename1filename2ButtonGroup.Value
if (app.xxButton.Value)
plotting = 'x-x'
elseif (app.xyButton.Value)
plotting = 'x-y'
elseif (app.yxButton.Value)
plotting = 'y-x'
elseif (app.yyButton.Value)
plotting = 'y-y'
end
% Load filename1 & filename2
global filename1_IMAG_REAL
global filename2_IMAG_REAL
% Legend
legend_filename1 = app.Legendforfilename1EditField.Value ;
legend_filename2 = app.Legendforfilename2EditField.Value ;
% Axis
x_label = app.LabelxaxisEditField.Value;
y_label = app.LabelyaxisEditField.Value;
% Title
title_plot= app.TitleEditField.Value;
run(filename1_IMAG_REAL) ;
comma2point_overwrite( filename1_IMAG_REAL ) ;
if strcmp(plotting, 'x-x') | strcmp(plotting, 'x-y')
[pks_Realx_max,pks_Realx_min,locs_Realx_max,locs_Realx_min,freqreduced,freqreduced_backup,Realx,Imagx,locs_Imagx,pks_Imagx] = Function_FRF_IMAG_REAL_AKA(Freq,Real1,Imag1,Rmv_X_data,find_peaksx,Smooth_signal,dots_value,Rmv_to_data) ;
elseif strcmp(plotting, 'y-x') | strcmp(plotting, 'y-y')
[pks_Realx_max,pks_Realx_min,locs_Realx_max,locs_Realx_min,freqreduced,freqreduced_backup,Realx,Imagx,locs_Imagx,pks_Imagx] = Function_FRF_IMAG_REAL_AKA(Freq,Real2,Imag2,Rmv_X_data,find_peaksx,Smooth_signal,dots_value,Rmv_to_data) ;
end
% Filename2 = first matlab file
run(filename2_IMAG_REAL) ;
comma2point_overwrite( filename2_IMAG_REAL ) ;
if strcmp(plotting, 'x-x') | strcmp(plotting, 'y-x')
[pks_Realx_max2,pks_Realx_min2,locs_Realx_max2,locs_Realx_min2,freqreduced2,freqreduced_backup,Realx2,Imagx2,locs_Imagx2,pks_Imagx2] = Function_FRF_IMAG_REAL_AKA(Freq,Real1,Imag1,Rmv_X_data,find_peaksx,Smooth_signal,dots_value,Rmv_to_data) ;
elseif strcmp(plotting, 'x-y') | strcmp(plotting, 'y-y')
[pks_Realx_max2,pks_Realx_min2,locs_Realx_max2,locs_Realx_min2,freqreduced2,freqreduced_backup,Realx2,Imagx2,locs_Imagx2,pks_Imagx2] = Function_FRF_IMAG_REAL_AKA(Freq,Real2,Imag2,Rmv_X_data,find_peaksx,Smooth_signal,dots_value,Rmv_to_data) ;
end
if strcmp(dots_value, 'on')
plot(app.UIAxes,freqreduced, Imagx,'g','linewidth',1.2)
hold(app.UIAxes, 'on')
plot(app.UIAxes,freqreduced2, Imagx2,'r','linewidth',1.2)
hold(app.UIAxes, 'on')
plot(app.UIAxes,locs_Imagx,pks_Imagx,'go','linewidth',1.2) % Plots the circles
hold(app.UIAxes, 'on')
plot(app.UIAxes,locs_Imagx2,pks_Imagx2,'ro','linewidth',1.2) % Plots the circles
hold(app.UIAxes, 'on')
for j=1:length(locs_Imagx)
Imag_1 = text(app.UIAxes, round(locs_Imagx(:,j)'),pks_Imagx(j,:),num2str(round(locs_Imagx(:,j))), ...
'HorizontalAlignment', 'left', 'VerticalAlignment', 'top', ...
'fontweight','bold','fontsize',14); % Plot the values
set(Imag_1, 'Color',[0, 1 ,0]) ;
end
hold(app.UIAxes)
for j=1:length(locs_Imagx2)
Imag_2 = text(app.UIAxes, round(locs_Imagx2(:,j)'),pks_Imagx2(j,:),num2str(round(locs_Imagx2(:,j))), ...
'HorizontalAlignment', 'right', 'VerticalAlignment', 'top', ...
'fontweight','bold','fontsize',14); % Plot the values
set(Imag_2, 'Color',[1, 0 ,0]) ;
end
hold(app.UIAxes, 'on')
title(app.UIAxes, title_plot)
legend(app.UIAxes, legend_filename1,legend_filename2,'Location','southeast')
xlabel(app.UIAxes, x_label)
ylabel(app.UIAxes, y_label)
xlim(app.UIAxes, [freqreduced(1)-10 freqreduced(end)+10])
elseif strcmp(dots_value, 'off')
plot(app.UIAxes,freqreduced, Imagx,'g','linewidth',1.2)
hold(app.UIAxes, 'on')
plot(app.UIAxes,freqreduced2, Imagx2,'r','linewidth',1.2)
end
title(app.UIAxes, title_plot)
legend(app.UIAxes, legend_filename1,legend_filename2,'Location','southeast')
xlabel(app.UIAxes, x_label)
ylabel(app.UIAxes, y_label)
xlim(app.UIAxes, [freqreduced(1)-10 freqreduced(end)+10])
end
% Button pushed function: Filename2mButton
function Filename2mButtonPushed(app, event)
[file2,path2] = uigetfile('*.m') %open a matlab file
global filename2_IMAG_REAL
filename2_IMAG_REAL=fullfile(path2,file2);
end
% Value changing function: Legendforfilename1EditField
function Legendforfilename1EditFieldValueChanging(app, event)
end
% Value changed function: Legendforfilename1EditField
function Legendforfilename1EditFieldValueChanged(app, event)
value = app.Legendforfilename1EditField.Value;
end
% Value changed function: TitleEditField
function TitleEditFieldValueChanged(app, event)
value = app.TitleEditField.Value;
end
% Value changed function: LabelyaxisEditField
function LabelyaxisEditFieldValueChanged(app, event)
value = app.LabelyaxisEditField.Value;
end
% Value changed function: LabelxaxisEditField
function LabelxaxisEditFieldValueChanged(app, event)
value = app.LabelxaxisEditField.Value;
end
% Value changed function: Legendforfilename2EditField
function Legendforfilename2EditFieldValueChanged(app, event)
value = app.Legendforfilename2EditField.Value;
end
% Changes arrangement of the app based on UIFigure width
function updateAppLayout(app, event)
currentFigureWidth = app.UIFigure.Position(3);
if(currentFigureWidth <= app.onePanelWidth)
% Change to a 2x1 grid
app.GridLayout.RowHeight = {480, 480};
app.GridLayout.ColumnWidth = {'1x'};
app.RightPanel.Layout.Row = 2;
app.RightPanel.Layout.Column = 1;
else
% Change to a 1x2 grid
app.GridLayout.RowHeight = {'1x'};
app.GridLayout.ColumnWidth = {269, '1x'};
app.RightPanel.Layout.Row = 1;
app.RightPanel.Layout.Column = 2;
end
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.AutoResizeChildren = 'off';
app.UIFigure.Position = [100 100 640 480];
app.UIFigure.Name = 'UI Figure';
app.UIFigure.SizeChangedFcn = createCallbackFcn(app, @updateAppLayout, true);
% Create GridLayout
app.GridLayout = uigridlayout(app.UIFigure);
app.GridLayout.ColumnWidth = {269, '1x'};
app.GridLayout.RowHeight = {'1x'};
app.GridLayout.ColumnSpacing = 0;
app.GridLayout.RowSpacing = 0;
app.GridLayout.Padding = [0 0 0 0];
app.GridLayout.Scrollable = 'on';
% Create LeftPanel
app.LeftPanel = uipanel(app.GridLayout);
app.LeftPanel.Layout.Row = 1;
app.LeftPanel.Layout.Column = 1;
% Create TabGroup
app.TabGroup = uitabgroup(app.LeftPanel);
app.TabGroup.Position = [1 6 262 473];
% Create InputsTab
app.InputsTab = uitab(app.TabGroup);
app.InputsTab.Title = 'Inputs';
% Create OnButton
app.OnButton = uibutton(app.InputsTab, 'push');
app.OnButton.ButtonPushedFcn = createCallbackFcn(app, @OnButtonPushed, true);
app.OnButton.FontWeight = 'bold';
app.OnButton.Position = [138 420 100 22];
app.OnButton.Text = {'On'; ''};
% Create OffButton
app.OffButton = uibutton(app.InputsTab, 'push');
app.OffButton.ButtonPushedFcn = createCallbackFcn(app, @OffButtonPushed, true);
app.OffButton.FontWeight = 'bold';
app.OffButton.Position = [137 391 100 22];
app.OffButton.Text = {'Off'; ''};
% Create OnButton_4
app.OnButton_4 = uibutton(app.InputsTab, 'push');
app.OnButton_4.ButtonPushedFcn = createCallbackFcn(app, @OnButton_4Pushed, true);
app.OnButton_4.FontWeight = 'bold';
app.OnButton_4.Position = [138 267 100 22];
app.OnButton_4.Text = {'On'; ''};
% Create OffButton_4
app.OffButton_4 = uibutton(app.InputsTab, 'push');
app.OffButton_4.ButtonPushedFcn = createCallbackFcn(app, @OffButton_4Pushed, true);
app.OffButton_4.FontWeight = 'bold';
app.OffButton_4.Position = [138 239 100 22];
app.OffButton_4.Text = {'Off'; ''};
% Create OnButton_2
app.OnButton_2 = uibutton(app.InputsTab, 'push');
app.OnButton_2.ButtonPushedFcn = createCallbackFcn(app, @OnButton_2Pushed, true);
app.OnButton_2.FontWeight = 'bold';
app.OnButton_2.Position = [137 342 100 22];
app.OnButton_2.Text = {'On'; ''};
% Create OffButton_2
app.OffButton_2 = uibutton(app.InputsTab, 'push');
app.OffButton_2.ButtonPushedFcn = createCallbackFcn(app, @OffButton_2Pushed, true);
app.OffButton_2.FontWeight = 'bold';
app.OffButton_2.Position = [137 314 100 22];
app.OffButton_2.Text = {'Off'; ''};
% Create Filename1mButton
app.Filename1mButton = uibutton(app.InputsTab, 'push');
app.Filename1mButton.ButtonPushedFcn = createCallbackFcn(app, @Filename1mButtonPushed, true);
app.Filename1mButton.Position = [7 145 100 22];
app.Filename1mButton.Text = 'Filename1 (.m)';
% Create Filename2mButton
app.Filename2mButton = uibutton(app.InputsTab, 'push');
app.Filename2mButton.ButtonPushedFcn = createCallbackFcn(app, @Filename2mButtonPushed, true);
app.Filename2mButton.Position = [138 145 100 22];
app.Filename2mButton.Text = 'Filename2 (.m)';
% Create RemovethefirstXnumberofdataLabel
app.RemovethefirstXnumberofdataLabel = uilabel(app.InputsTab);
app.RemovethefirstXnumberofdataLabel.HorizontalAlignment = 'center';
app.RemovethefirstXnumberofdataLabel.FontWeight = 'bold';
app.RemovethefirstXnumberofdataLabel.Position = [5 415 114 27];
app.RemovethefirstXnumberofdataLabel.Text = {'Remove the first X '; 'number of data'};
% Create RemovethefirstXnumberofdataEditField
app.RemovethefirstXnumberofdataEditField = uieditfield(app.InputsTab, 'numeric');
app.RemovethefirstXnumberofdataEditField.ValueChangedFcn = createCallbackFcn(app, @RemovethefirstXnumberofdataEditFieldValueChanged, true);
app.RemovethefirstXnumberofdataEditField.HorizontalAlignment = 'center';
app.RemovethefirstXnumberofdataEditField.FontWeight = 'bold';
app.RemovethefirstXnumberofdataEditField.Position = [8 390 100 22];
% Create RemovethelastXnumberofdataEditFieldLabel
app.RemovethelastXnumberofdataEditFieldLabel = uilabel(app.InputsTab);
app.RemovethelastXnumberofdataEditFieldLabel.HorizontalAlignment = 'center';
app.RemovethelastXnumberofdataEditFieldLabel.FontWeight = 'bold';
app.RemovethelastXnumberofdataEditFieldLabel.Position = [6 336 112 27];
app.RemovethelastXnumberofdataEditFieldLabel.Text = {'Remove the last X '; 'number of data '};
% Create RemovethelastXnumberofdataEditField
app.RemovethelastXnumberofdataEditField = uieditfield(app.InputsTab, 'numeric');
app.RemovethelastXnumberofdataEditField.ValueChangedFcn = createCallbackFcn(app, @RemovethelastXnumberofdataEditFieldValueChanged, true);
app.RemovethelastXnumberofdataEditField.HorizontalAlignment = 'center';
app.RemovethelastXnumberofdataEditField.FontWeight = 'bold';
app.RemovethelastXnumberofdataEditField.Position = [8 308 100 22];
% Create NumberofpeaksinIMAGXLabel
app.NumberofpeaksinIMAGXLabel = uilabel(app.InputsTab);
app.NumberofpeaksinIMAGXLabel.HorizontalAlignment = 'center';
app.NumberofpeaksinIMAGXLabel.FontWeight = 'bold';
app.NumberofpeaksinIMAGXLabel.Position = [6 190 103 27];
app.NumberofpeaksinIMAGXLabel.Text = {'Number of peaks'; 'in IMAG X '};
% Create NumberofpeaksinIMAGXEditField
app.NumberofpeaksinIMAGXEditField = uieditfield(app.InputsTab, 'numeric');
app.NumberofpeaksinIMAGXEditField.Limits = [1 Inf];
app.NumberofpeaksinIMAGXEditField.ValueChangedFcn = createCallbackFcn(app, @NumberofpeaksinIMAGXEditFieldValueChanged, true);
app.NumberofpeaksinIMAGXEditField.HorizontalAlignment = 'center';
app.NumberofpeaksinIMAGXEditField.FontWeight = 'bold';
app.NumberofpeaksinIMAGXEditField.Position = [136 195 100 22];
app.NumberofpeaksinIMAGXEditField.Value = 1;
% Create SmoothSignalEditFieldLabel
app.SmoothSignalEditFieldLabel = uilabel(app.InputsTab);
app.SmoothSignalEditFieldLabel.HorizontalAlignment = 'center';
app.SmoothSignalEditFieldLabel.FontWeight = 'bold';
app.SmoothSignalEditFieldLabel.Position = [9 263 88 22];
app.SmoothSignalEditFieldLabel.Text = 'Smooth Signal';
% Create SmoothSignalEditField
app.SmoothSignalEditField = uieditfield(app.InputsTab, 'numeric');
app.SmoothSignalEditField.Limits = [1 Inf];
app.SmoothSignalEditField.ValueChangedFcn = createCallbackFcn(app, @SmoothSignalEditFieldValueChanged, true);
app.SmoothSignalEditField.HorizontalAlignment = 'center';
app.SmoothSignalEditField.FontWeight = 'bold';
app.SmoothSignalEditField.Position = [8 240 100 22];
app.SmoothSignalEditField.Value = 1;
% Create Plotfilename1filename2ButtonGroup
app.Plotfilename1filename2ButtonGroup = uibuttongroup(app.InputsTab);
app.Plotfilename1filename2ButtonGroup.SelectionChangedFcn = createCallbackFcn(app, @OnButtonPushed, true);
app.Plotfilename1filename2ButtonGroup.TitlePosition = 'centertop';
app.Plotfilename1filename2ButtonGroup.Title = 'Plot (filename1-filename2)';
app.Plotfilename1filename2ButtonGroup.FontWeight = 'bold';
app.Plotfilename1filename2ButtonGroup.Position = [9 7 159 130];
% Create xxButton
app.xxButton = uitogglebutton(app.Plotfilename1filename2ButtonGroup);
app.xxButton.Text = 'x-x';
app.xxButton.Position = [20 77 100 22];
app.xxButton.Value = true;
% Create xyButton
app.xyButton = uitogglebutton(app.Plotfilename1filename2ButtonGroup);
app.xyButton.Text = 'x-y';
app.xyButton.Position = [20 56 100 22];
% Create yxButton
app.yxButton = uitogglebutton(app.Plotfilename1filename2ButtonGroup);
app.yxButton.Text = 'y-x';
app.yxButton.Position = [20 35 100 22];
% Create yyButton
app.yyButton = uitogglebutton(app.Plotfilename1filename2ButtonGroup);
app.yyButton.Text = 'y-y';
app.yyButton.Position = [20 14 100 22];
% Create DotsvalueSwitchLabel
app.DotsvalueSwitchLabel = uilabel(app.InputsTab);
app.DotsvalueSwitchLabel.HorizontalAlignment = 'center';
app.DotsvalueSwitchLabel.FontWeight = 'bold';
app.DotsvalueSwitchLabel.Position = [175 25 78 22];
app.DotsvalueSwitchLabel.Text = 'Dots & value';
% Create DotsvalueSwitch
app.DotsvalueSwitch = uiswitch(app.InputsTab, 'slider');
app.DotsvalueSwitch.ValueChangedFcn = createCallbackFcn(app, @DotsvalueSwitchValueChanged, true);
app.DotsvalueSwitch.FontWeight = 'bold';
app.DotsvalueSwitch.Position = [190 62 45 20];
app.DotsvalueSwitch.Value = 'On';
% Create Inputs2Tab
app.Inputs2Tab = uitab(app.TabGroup);
app.Inputs2Tab.Title = 'Inputs2';
% Create Legendforfilename1EditFieldLabel
app.Legendforfilename1EditFieldLabel = uilabel(app.Inputs2Tab);
app.Legendforfilename1EditFieldLabel.HorizontalAlignment = 'center';
app.Legendforfilename1EditFieldLabel.FontWeight = 'bold';
app.Legendforfilename1EditFieldLabel.Position = [9 414 126 22];
app.Legendforfilename1EditFieldLabel.Text = 'Legend for filename1';
% Create Legendforfilename1EditField
app.Legendforfilename1EditField = uieditfield(app.Inputs2Tab, 'text');
app.Legendforfilename1EditField.ValueChangedFcn = createCallbackFcn(app, @Legendforfilename1EditFieldValueChanged, true);
app.Legendforfilename1EditField.ValueChangingFcn = createCallbackFcn(app, @Legendforfilename1EditFieldValueChanging, true);
app.Legendforfilename1EditField.Tooltip = {''};
app.Legendforfilename1EditField.Position = [9 386 243 25];
app.Legendforfilename1EditField.Value = 'Pre-Treatment';
% Create Legendforfilename2EditFieldLabel
app.Legendforfilename2EditFieldLabel = uilabel(app.Inputs2Tab);
app.Legendforfilename2EditFieldLabel.HorizontalAlignment = 'center';
app.Legendforfilename2EditFieldLabel.FontWeight = 'bold';
app.Legendforfilename2EditFieldLabel.Position = [9 345 126 22];
app.Legendforfilename2EditFieldLabel.Text = 'Legend for filename2';
% Create Legendforfilename2EditField
app.Legendforfilename2EditField = uieditfield(app.Inputs2Tab, 'text');
app.Legendforfilename2EditField.ValueChangedFcn = createCallbackFcn(app, @Legendforfilename2EditFieldValueChanged, true);
app.Legendforfilename2EditField.Position = [9 317 243 25];
app.Legendforfilename2EditField.Value = 'Post-Treatment';
% Create LabelxaxisEditFieldLabel
app.LabelxaxisEditFieldLabel = uilabel(app.Inputs2Tab);
app.LabelxaxisEditFieldLabel.HorizontalAlignment = 'center';
app.LabelxaxisEditFieldLabel.FontWeight = 'bold';
app.LabelxaxisEditFieldLabel.Position = [9 284 74 22];
app.LabelxaxisEditFieldLabel.Text = 'Label x-axis';
% Create LabelxaxisEditField
app.LabelxaxisEditField = uieditfield(app.Inputs2Tab, 'text');
app.LabelxaxisEditField.ValueChangedFcn = createCallbackFcn(app, @LabelxaxisEditFieldValueChanged, true);
app.LabelxaxisEditField.Position = [9 253 243 25];
app.LabelxaxisEditField.Value = 'Frequency';
% Create LabelyaxisEditFieldLabel
app.LabelyaxisEditFieldLabel = uilabel(app.Inputs2Tab);
app.LabelyaxisEditFieldLabel.HorizontalAlignment = 'center';
app.LabelyaxisEditFieldLabel.FontWeight = 'bold';
app.LabelyaxisEditFieldLabel.Position = [9 213 74 22];
app.LabelyaxisEditFieldLabel.Text = 'Label y-axis';
% Create LabelyaxisEditField
app.LabelyaxisEditField = uieditfield(app.Inputs2Tab, 'text');
app.LabelyaxisEditField.ValueChangedFcn = createCallbackFcn(app, @LabelyaxisEditFieldValueChanged, true);
app.LabelyaxisEditField.Position = [9 188 243 25];
app.LabelyaxisEditField.Value = 'Amplitude';
% Create TitleEditFieldLabel
app.TitleEditFieldLabel = uilabel(app.Inputs2Tab);
app.TitleEditFieldLabel.HorizontalAlignment = 'right';
app.TitleEditFieldLabel.FontWeight = 'bold';
app.TitleEditFieldLabel.Position = [9 149 33 22];
app.TitleEditFieldLabel.Text = 'Title ';
% Create TitleEditField
app.TitleEditField = uieditfield(app.Inputs2Tab, 'text');
app.TitleEditField.ValueChangedFcn = createCallbackFcn(app, @TitleEditFieldValueChanged, true);
app.TitleEditField.Position = [9 123 243 25];
app.TitleEditField.Value = 'Imag Oriented Frequency Response';
% Create RunButton
app.RunButton = uibutton(app.Inputs2Tab, 'push');
app.RunButton.ButtonPushedFcn = createCallbackFcn(app, @RunButtonPushed, true);
app.RunButton.FontWeight = 'bold';
app.RunButton.Position = [9 20 243 54];
app.RunButton.Text = {'Run'; ''};
% Create RightPanel
app.RightPanel = uipanel(app.GridLayout);
app.RightPanel.Layout.Row = 1;
app.RightPanel.Layout.Column = 2;
% Create UIAxes
app.UIAxes = uiaxes(app.RightPanel);
title(app.UIAxes, 'Title')
xlabel(app.UIAxes, 'X')
ylabel(app.UIAxes, 'Y')
app.UIAxes.Position = [1 6 364 473];
% 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 = App
% 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

Answers (1)

Walter Roberson
Walter Roberson on 1 Apr 2020
Edited: Walter Roberson on 1 Apr 2020
Compiled applications can only run() scripts that were compiled into the applications.
When you obtain a file name from the user and attempt to run() it, you are effectively permitting the user to run arbitrary code, which requires that the MATLAB parser be available. Compiled applications cannot run arbitrary code: the MATLAB parser is not present, and they can only execute code that has already been analyzed and converted to binary at compile time.
If you were to provide a listbox or dropdown that permitted the user to select from one of several pre-determined files, rather than being able to name arbitrary files, then you would be able to tell the application compiler to include that particular files. But since those files are pre-determined and will be compiled in, it would be better to convert the scripts into functions. Scripts can have odd effects...
  4 Comments
Walter Roberson
Walter Roberson on 2 Apr 2020
No, there is no way around this, and there never will be.
This is a deliberate design decision on the part of Mathworks.
The ability to run user-provided code in compiled application would give the user the ability to run arbitrary code, and therefore to do everything that could be done in MATLAB (except perhaps use some of the tools such as the Curve Fitting Tool). That would make every free compiled application into nearly a full version of paid MATLAB.
If you need the user to be able to supply code at run time, then you need a full version of MATLAB, not a compiled app.
Mücahid Kacar
Mücahid Kacar on 3 Apr 2020
ok thank you for the reply!
Appreciate your time.

Sign in to comment.

Categories

Find more on Develop uifigure-Based Apps in Help Center and File Exchange

Products


Release

R2019b

Community Treasure Hunt

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

Start Hunting!