How do I save a figure to a different directory with a specific figure name?
조회 수: 15 (최근 30일)
이전 댓글 표시
I am trying to save a figure with the type and dateTime variables included in the savefile name. My code uses the input variable " type = 'Triangle' " in order to run, and it saves the start time as a dateTime variable. I want the "type" variable to save based on it's input so that the saved figure will include any string assigned to "type." I am also trying to save the figure to a different directory.
I have a code that uses the variable " type = 'Triangle' " when running the code and saves the time I start running the code as f. I want to save that string variable with the date & time as part of the figure name. I'm trying to also save this figure to a different directory that my code is not in.
This is what I have so far but I am getting the following error: H must be an array of handles to valid figures.
type = 'Triangle';
folderName = 'C:\my\directory';
savefig(fullfile(folderName,[datestr(startTime) type]));
댓글 수: 0
채택된 답변
Fangjun Jiang
2022년 2월 28일
savefig(FILENAME) saves the current figure to a file named FILENAME
savefig(H, FILENAME) saves the figures identified by the graphics
handle array H to a MATLAB figure file called FILENAME.
To be robust, specify H and make sure your file name is valid.
H=figure
plot(1:10)
savefig(H, 'myFigure')
댓글 수: 0
추가 답변 (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!