Setting current directory as save location for executable guis?

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일

0 개 추천

For Windows, the attached function works to find the "real" folder where the executable is, which is not where mfilename says it is.

댓글 수: 2

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')
No. You'd do something like
executableFolder] = GetExecutableFolder();
%Later in my code
fullFileName = fullfile(executableFolder, 'DataSummary.xlsx');
xlswrite(fullFileName , DataSummary,1,'A2')

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

질문:

2015년 4월 27일

댓글:

2015년 4월 27일

Community Treasure Hunt

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

Start Hunting!

Translated by