Borrar filtros
Borrar filtros

Error on saving .fig files

51 visualizaciones (últimos 30 días)
Susan
Susan el 10 de Abr. de 2023
Editada: Susan el 12 de Abr. de 2023
Hi All,
I have a nested for loop, and at the very last for loop, I plot the data and save them as a ".fig" in a folder. It works well for the first 7 figs but then gives me the error saying, "The file could not be closed and might now be corrupt." I ensure to close each figure after saving them out and don't get what this error is about. Any help would be appreciated.

Respuesta aceptada

Praveen Reddy
Praveen Reddy el 12 de Abr. de 2023
Hi Susan,
I understand that you are encountering an error while trying to save plotted data in every iteration of a “for” loop as .FIG files in a directory . You can create a figure window before the for loop and make sure you clear the plot after saving the figure in each iteration. Attaching simple code snippet for your reference.
h=figure;
for i=1:5
x=linspace(i,i+10);
y=linspace(i+20,i+30);
plot(x,y);
saveas(h,sprintf('FIG%d.fig',i)); % will create FIG1, FIG2,...
clf(f);
end
The error you are facing could also be due to character encoding, which can be resolved in preferences. Go to Home>Preferences>General>MAT-Files and make sure that you have chosen “Version 7.0 or later” or “Version 7.3 or later”.
  1 comentario
Susan
Susan el 12 de Abr. de 2023
Editada: Susan el 12 de Abr. de 2023
@Praveen Reddy Thank you so much for the suggestions. They solved the issue :)

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Printing and Saving en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by