Error in savefig command
2 ビュー (過去 30 日間)
古いコメントを表示
I used the following code in matlab in odrer to save my figures:
FolderName = tempdir; % Your destination folder
FigList = findobj(allchild(0), 'flat', 'Type', 'figure');
for iFig = 1:length(FigList)
FigHandle = FigList(iFig);
FigName = get(FigHandle, 'Name');
savefig(FigHandle, fullfile(FolderName, FigName, '.fig'));
end
Adjust the FigName to your needs.
but I get this: "Undefined function 'savefig' for input arguments of type 'double'." My version of Matlab does not have the command "savefig". Can anyone help me by giving me the code of this command, or propose to me an alternative way of saving my plots automatically in a folder of my choice ?
0 件のコメント
回答 (1 件)
Anudeep Kumar
2025 年 6 月 4 日
編集済み: Anudeep Kumar
2025 年 6 月 4 日
Hey Konstantinos,
I believe the error being thrown could be due to 'savefig' being called with an incorrect input type.
As per the documentation, 'savefig' expects a figure handle, but it could be the case that 'FigHandle' is not a valid figure handle.
To resolve this error, make sure 'FigHandle' is a valid figure handle and not a double or invalid reference.
In case you are using MATLAB version prior to R2013b, 'savefig' will not be available. You can use 'saveas' instead.
Here is an alternative code using 'saveas' function
FolderName = tempdir; % Destination folder
FigList = findobj(allchild(0), 'flat', 'Type', 'figure');
for iFig = 1:length(FigList)
FigHandle = FigList(iFig);
FigName = get(FigHandle, 'Name');
% Save the figure as .fig using saveas
saveas(FigHandle, fullfile(FolderName, [FigName '.fig']));
end
I have attached the documentation for 'savefig' :
and 'saveas' for your reference
Hope it helps!
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Printing and Saving についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!