Can't open .fig file saved by saveas command on script
6 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Please help understanding why I can't open a file generated by save as command on a script.
I tried:
saveas(gcf,'Graph.fig')
and
savefig('Graph.fig')
The code generates a file like the attached one. The file, if double clicked, opens Matlab program but nothing is shown. I use similar code to generate .eps and .png files and they are fine.
If I manually do "Save as" it generates a similar sized file that opens fine.
Please bear in mind I have very limited skills with Matlab.
Any help appreciated.
1 commentaire
Mathijs Geurts
le 20 Juil 2021
I just started using Matlab and I am experiencing exactly the same problem. Have you managed to solve your problem in the end?
Or is there anyone else that understands what goes wrong and knows how to solve this poblem?
saveas(gcf,fullfile(figuresdir,'example fig figure1'),'fig');
saveas(gcf,fullfile(figuresdir,'example fig figure2'),'png');
Any help would be much appreciated.
Mathijs
Réponses (2)
Walter Roberson
le 9 Fév 2018
fig = openfig('Graph.fig');
set(fig, 'Visible', 'on')
That is, the figure happened to be saved when it was set to invisible.
6 commentaires
Walter Roberson
le 22 Mar 2018
We understand the request -- it is just not at all easy to implement. As soon as you change the visibility flag to make it visible, it is likely to render before you can save it (confirmed in my test.) Therefore in order to meet your requirement, you would have to save the figure with the visible flag off, and then have some code that modified the binary version of the .fig .
If you always want the figure to become visible as soon as it is opened, then I recommend a quite different approach:
Leave the figure 'visible' flag off at the time of your saving the figure, but first set the figure CreateFcn callback to @(src,event) set(src,'Visible','on')
Stephen23
le 22 Mar 2018
Modifié(e) : Stephen23
le 22 Mar 2018
"The reason is that I have many graphs being generated..."
Why not avoid the whole problem by using just one figure (or a few figures)? For reasons of simplicity (i.e. defining and accessing graphics handles) and efficiency this is what experienced users often do, simply updating and replacing any data/axes/... as required. You could easily save each iteration as its own .fig file.
"I would like them to NOT open all at once and spam my pc window"
Spamming lots of figures is something that beginners do before they learn how to use graphics handles and update their graphics instead of just generating more and more and more figures. There is no reason why you need to spam anything anywhere, even if plotting lots of things in a loop.
Create just one figure, obtain its figure handle explicitly, send it to the back of the graphics stack, and then keep on working. Always obtain and use all graphics handles explicitly.
All of these other suggestions might work, but they are hacks to fix something that would be better avoided by fixing the problem at the source, not by affixing a Band-Aid afterwards.
reyadh Albarakat
le 9 Fév 2018
1 commentaire
Steeven
le 1 Mar 2018
Hi Reyadh. Would you mind explaining or giving an example of how to "install" and how to use this function? I do not seem to have success with it.
Voir également
Catégories
En savoir plus sur Environment and Settings dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!