Setting current directory as save location for executable guis?

1 visualización (últimos 30 días)
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?

Respuesta aceptada

Image Analyst
Image Analyst el 27 de Abr. de 2015
For Windows, the attached function works to find the "real" folder where the executable is, which is not where mfilename says it is.
  2 comentarios
matlabuser12
matlabuser12 el 27 de Abr. de 2015
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 el 27 de Abr. de 2015
No. You'd do something like
executableFolder] = GetExecutableFolder();
%Later in my code
fullFileName = fullfile(executableFolder, 'DataSummary.xlsx');
xlswrite(fullFileName , DataSummary,1,'A2')

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Use COM Objects in MATLAB en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by