Matlab provides the movefile
function that can be used to rename one or more files. To rename a single file in Matlab, you can simply provide the old file name and the new file name as input arguments to the movefile
function:
main.m85 chars4 lines
To rename multiple files in a batch, you can use loops and regular expressions. For example, the following code renames all files in the current directory with the extension .jpg
:
main.m262 chars10 lines
This code uses the dir
function to get a list of all .jpg
files in the current directory. Then, it loops through each file and uses regexprep
to replace the .jpg
extension with _new.jpg
. Finally, it calls movefile
to rename the file.
gistlibby LogSnag