Clear Filters
Clear Filters

'saveas' does not overwrite existing image file

32 views (last 30 days)
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!
  1 Comment
Julia
Julia on 7 Nov 2018
Sorry, I just found that it does actually overwrite the file. However, on Windows 8.1 the date of the last modification date of this file is not updated so you can't easily see when the file was last modified. Is there another way of obtaining this information?

Sign in to comment.

Accepted Answer

Stephan
Stephan on 7 Nov 2018
Edited: Stephan on 7 Nov 2018
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

More Answers (0)

Categories

Find more on Printing and Saving in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!