Save figure array error: "H must be an array of handles to valid figures"
40 ビュー (過去 30 日間)
古いコメントを表示
I have a custom method from an internal codebase that creates a bunch of figures.
I have all the figures open in Matlab and I would like to save them. However, this gives and error:
fig = CustomStruct.CreateFigureCustomMethod;
savefig(fig, 'name.fig');
"Error using savefig (line 43)
H must be an array of handles to valid figures."
But fig is actually a Figure array in the workspace!
I know this may be impossible to answer due to reproducibilty, but I wonder if there is another way to save all open figures.
I could dig into the method and modify it, but I have the same issue with several methods and I do not think this should be necessary.
1 件のコメント
Ameer Hamza
2020 年 10 月 7 日
This error will happen if any of the figures is closed. If all figure windows are open, it should work fine.
採用された回答
Ameer Hamza
2020 年 10 月 7 日
Try this to only save figures that are currently open
idx = arrayfun(@ishandle, fig);
fig_new = fig(idx);
savefig(fig, 'name.fig');
4 件のコメント
Ameer Hamza
2020 年 10 月 7 日
I am glad to be of help! Yes, mathworks have made many improvements during recent releases. An upgrade will be a good option.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Interactive Control and Callbacks についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!