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'); |
% 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] = fileparts(FileName);
FileName = fullfile(filepath, 'results', [filename, ext]);
fullpath = fullfile(filepath, 'results');
createDir(fullpath); |
[filepath, filename, ext] = fileparts(FileName);
FileName = fullfile(filepath, 'results', [filename, ext]);
fullpath = fullfile(filepath, 'results');
createDir(fullpath);
Where
createDir
is the following function
function createDir(pathstr)
if(~exist([pathstr], 'dir'))
mkdir(pathstr)
end |
function createDir(pathstr)
if(~exist([pathstr], 'dir'))
mkdir(pathstr)
end
Ähnliche Beiträge