Saving of MATLAB Image File not consistent

조회 수: 6 (최근 30일)
Amritesh Maitra
Amritesh Maitra 2024년 5월 28일
댓글: Amritesh Maitra 2024년 5월 30일
I have written a code to generate several plots from an array of data. Whenever I am trying to save those image files by savefig (for .fig Matlab files) or by saveas as jpeg or eps format, the saving of the image files is inconsistent. For a group of plots, savefig('FileName.fig') and saveas(gcf,'FileNameeps','eps') are working, i.e., images are saved in the current folder. However, sometimes the newly generated plots are not overwriting the previously generated plots (for some other runs) in the folder.
I have tried including the following before each plot:
delete FileName FileNameeps
But the problem persists. Only when I manually delete all the previous image files from the previous runs for the current folder, newer plots are saved. What can be a fix? Such problem did not occur when I had to generate fewer plots (as in codes generating one dozen plots in stead of some 4 dozen plots)
Thanks in advance.
  댓글 수: 1
Amritesh Maitra
Amritesh Maitra 2024년 5월 30일
I sort of managed the situation following Ninad's advice. But I would like to knoe the cause of the issue, as it had not cropped up before. Has anybody else faced such issues?

댓글을 달려면 로그인하십시오.

채택된 답변

Ninad
Ninad 2024년 5월 28일
Hi Amritesh,
I recommend running a check to delete the image file if it already exists in the current working directory before saving the new plot using the same name. This approach helps in avoiding any potential issues with file overwriting.
To assist you with this, I've attached a dummy script named "deleteFig.m" that performs this task.
I hope you find this helpful.
Regards,
Ninad
  댓글 수: 1
Amritesh Maitra
Amritesh Maitra 2024년 5월 30일
Thanks Ninad for your response. Following your cue, I went through the MATLAB help section and feel isfile is a more suitable function, at least that is what MATLAB recommends. I entered all the files as a string and perform a loop search and delete operation to take care of my problem, as you had suggested in the dummy file.
Thanks.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Printing and Saving에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by