nav-left cat-right
Matthias Pospiech > Programming > matlab > change extension of filename

change extension of filename

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

Einen Kommentar schreiben

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind markiert *


This blog is kept spam free by WP-SpamFree.