Very often I tend to save the results of a file under the same name, but with a modified extension. This code shows how to achieve this
% change extension
[~, ~, ext] = fileparts(FileName);
FileName = strrep(FileName, ext, '-xyz.png');
If the file should be saved under a different folder it needs to be created and the file name changed accordingly
[filepath, filename, ext] =...