Setting current directory as save location for executable guis?

1 次查看(过去 30 天)
I have a gui that performs an xlswrite function and creates a file called summary.xlsx in a folder. When I turn this into an executable I want the current directory of that executable to replace that filepath in xlswrite. What does this code look like?

采纳的回答

Image Analyst
Image Analyst 2015-4-27
For Windows, the attached function works to find the "real" folder where the executable is, which is not where mfilename says it is.
  2 个评论
matlabuser12
matlabuser12 2015-4-27
Would the xlswrite code ultimately look like:
% Returns the folder where the compiled executable actually resides.
function [executableFolder] = GetExecutableFolder()
try
if isdeployed
% User is running an executable in standalone mode.
[status, result] = system('set PATH');
executableFolder = char(regexpi(result, 'Path=(.*?);', 'tokens', 'once'));
% fprintf(1, '\nIn function GetExecutableFolder(), currentWorkingDirectory = %s\n', executableFolder);
else
% User is running an m-file from the MATLAB integrated development environment (regular MATLAB).
executableFolder = pwd;
filename=[pwd,'Summary.xlsx']
end
catch ME
errorMessage = sprintf('Error in function %s() at line %d.\n\nError Message:\n%s', ...
ME.stack(1).name, ME.stack(1).line, ME.message);
uiwait(warndlg(errorMessage));
end
return;
%Later in my code
xlswrite(filename,DataSummary,1,'A2')
Image Analyst
Image Analyst 2015-4-27
No. You'd do something like
executableFolder] = GetExecutableFolder();
%Later in my code
fullFileName = fullfile(executableFolder, 'DataSummary.xlsx');
xlswrite(fullFileName , DataSummary,1,'A2')

请先登录,再进行评论。

更多回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by