Can't open .fig file saved by saveas command on script
조회 수: 6 (최근 30일)
이전 댓글 표시
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
Mathijs Geurts
2021년 7월 20일
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
답변 (2개)
Walter Roberson
2018년 2월 9일
fig = openfig('Graph.fig');
set(fig, 'Visible', 'on')
That is, the figure happened to be saved when it was set to invisible.
댓글 수: 6
Walter Roberson
2018년 3월 22일
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
2018년 3월 22일
편집: Stephen23
2018년 3월 22일
"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
2018년 2월 9일
댓글 수: 1
Steeven
2018년 3월 1일
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.
참고 항목
카테고리
Help Center 및 File Exchange에서 Environment and Settings에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!