Saving figures in m-file

18 ビュー (過去 30 日間)
Lizan
Lizan 2014 年 9 月 29 日
コメント済み: Lizan 2014 年 9 月 29 日
I am processing data and have several m-files at the time that I want to run and autosave .mat and .fig for the file.
I use following codes, like:
h(1) = figure
plot(x2,y2)
h(2) = figure
plot(x,y)
hold on
xlabel('x')
ylabel('log(y)')
save(mfilename)
savefig(h,[mfilename,'plots.fig']);
close(h)
It works fine the first time I run it. When I then go to a second .m file using same code I get the folioing error:
Error using savefig (line 33)
H must be an array of handles to valid figures.
Any idea what is wrong?
  2 件のコメント
Joseph Cheng
Joseph Cheng 2014 年 9 月 29 日
when you run the second m file are the figures still open? I see that in the fist one's example you close(h). if you do not reassign h then there isn't anything to save.
Lizan
Lizan 2014 年 9 月 29 日
Yes, I found what the error was, The problem was that I had forgot to assign one of the plots a h value so therefore the array was wrong.

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangePrinting and Saving についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by