MATLAB: Saving results to the specific location

image analysis

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

Best Answer

[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 );