I am trying to transfer a string (file location) from App Designer to a .m script file.
So far, in the App Designer I have:
app.matfile = app.matfileEditField.Value;
app.directory = app.DirectoryEditField.Value;
app.DataSetName = app.DataSetNameEditField.Value;
assignin('base','matfileDirectory',app.matfile);
assignin('base','directory',app.directory);
assignin('base','DataSetName',app.DataSetName);
run('PostProcessMAIN.m');
Where all the app.*** are public variables. When I run the app, the .m file correctly loads the three variables. When I go into the Command Window and test, the strings are correct. I also tried cd(directory) in the Command window to check to make sure it works and it does (cd puts you in the correct file path). I get an error though when the .m file runs by itself though. I get the following error:
Unrecognized function or variable 'directory'.
Error in PostProcessMAIN (line 10)
cd(directory);
Error in run (line 91)
evalin('caller', strcat(script, ';'));
Error in PDFscanner/PostProcessData (line 116)
run('PostProcessMAIN.m');
Error in
matlab.apps.AppBase>@(source,event)executeCallback(appdesigner.internal.service.AppManagementService.instance(),app,callback,requiresEventData,event) (line 63)
newCallback = @(source, event)executeCallback(appdesigner.internal.service.AppManagementService.instance(), ...
Error while evaluating Button PrivateButtonPushedFcn.
It doesn't recognize the variable that I assigned in and can use in the Command Window for some reason. Can anyone help me please?
Thank you for the help! To anyone having the same problem, here is the solution:
Make sure your variables are public:
properties (Access = public)
directory = '';
DataSetName = '';
matfile = '';
end
assign the app variable names from the text box in the application. Then assign in the variables to the .m file in the 'caller' workspace:
app.matfile = app.matfileEditField.Value;
app.directory = app.DirectoryEditField.Value;
app.DataSetName = app.DataSetNameEditField.Value;
assignin('caller','matfileDirectory',app.matfile);
assignin('caller','directory',app.directory);
assignin('caller','DataSetName',app.DataSetName);
evalin('caller','PostProcessMAIN');
NOTE: The .m file is PostProcessMAIN.m. However, if you put the .m in the line of script it won't recognize the file.
NOTE: Make sure you don't have 'clear' in the beginning of your .m file. This will clear all the variables you just assigned in and you will produce an error stating that the variables you are trying to use are not defined.