Setting current directory as save location for executable guis?

조회 수: 1 (최근 30일)
matlabuser12
matlabuser12 2015년 4월 27일
댓글: Image Analyst 2015년 4월 27일
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개)

카테고리

Help CenterFile Exchange에서 Use COM Objects in MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by