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 Center および File ExchangeUse 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