MATLAB Answers

0

Saving results to the specific location

Asked by Pankaj Dubey on 14 Jun 2018 at 23:08
Latest activity Commented on by Walter Roberson
on 15 Jun 2018 at 15:36

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

  0 Comments

Sign in to comment.

1 Answer

Answer by Walter Roberson
on 15 Jun 2018 at 0:55
 Accepted 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 );

  2 Comments

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.

Should probably have been

[FileName, folder] = uiputfile({'*.xls'},'Save As...', folder);

Sign in to comment.


Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today