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!