nav-left cat-right
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');
createDir(fullpath);
Where createDir is the following function
function createDir(pathstr)
if(~exist([pathstr], 'dir'))
    mkdir(pathstr)
end

Einen Kommentar schreiben

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


*

Du kannst folgende HTML-Tags benutzen: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

WP-SpamFree by Pole Position Marketing