Saving results to the specific location

1 view (last 30 days)
Hi, I am a novice coder, just started. I am doing an analysis on a image and eventually extract a excel files with values. I start the code with uigetfile and end with save as with uiputfile. How can I change the end of the code so that my 'save as' location is same as the from where I picked up the Image file. Basically I would like to make the default 'save as' location to the same folder where my images are. uiputfile is not neccessay here if I can directly save in the folder. I hope I made sense. thank you
my codes-
if true
%
defaultFileName = fullfile('*.tif*');
[baseFileName, folder] = uigetfile(fullfile('*.tif*'),'select a file');
fullFileName = fullfile(folder, baseFileName)
Image = imread(fullFileName);
% some formula_results
[FileName, folder] = uiputfile({'*.xls'},'Save As...',[xlfilename '.xls']);
xlswrite([folder FileName ],formula_results);
end

Accepted Answer

Walter Roberson
Walter Roberson on 15 Jun 2018
[FileName, folder] = uiputfile({'*.xls'},'Save As...', [xlfilename '.xls'], folder);
to give the folder as the default location.
But what you are probably looking for is
[~, basename, ~] = fileparts(fullFileName);
newFullName = fullfile(folder, [basename '.xls']);
xlswrite( newFullName, formula_results );
  2 Comments
Pankaj Dubey
Pankaj Dubey on 15 Jun 2018
This works beautifully! Thank you so much! Just wondering when I tried the first one, it gives errors
"Extraneous arguments entered, please check the documentation.
"[dialog_filter, dialog_title, dialog_filename, dialog_pathname, dialog_multiselect] = parseArguments();" " When I print folder, I do get the previous folder's path.
thank you again.
Walter Roberson
Walter Roberson on 15 Jun 2018
Should probably have been
[FileName, folder] = uiputfile({'*.xls'},'Save As...', folder);

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!