MATLAB: ‘saveas’ does not overwrite existing image file

overwritesaveas

Hello!
My script plots some points on an image ('whatever.tif') and should subsequently save the resulting figure using 'saveas' (as 'whatever_points.tif'). This works fine if there is no file 'whatever_points.tif' in the output folder yet. If 'whatever_points.tif' exists already in this folder, nothing seems to happen, i. e. the figure is not saved. I would, however, like the script to overwrite the preexisting figure if there is one. I thought this was the default but it clearly doesn't seem to be?
This is what I use for saving:
filename_image = 'D:\somefolder\whatever.tif'
figure_name = [filename_image(1:end-4), '_points'];
figure_format = filename_image(end-2:end);
saveas(gcf,figure_name, figure_format);
Thanks for your help!

Best Answer

Hi,
see this contribution from Mathworks Support Team:
>> info = dir('Untitled.m')
info =
struct with fields:
name: 'Untitled.m'
folder: 'W:\Matlab\Projekte'
date: '10-Jul-2018 16:32:29'
bytes: 65
isdir: 0
datenum: 7.3725e+05
The date field in this structure is the last modification date.
Best regards
Stephan