Problem by saveas plot
이전 댓글 표시
Hi everyone, I do not understand what I'am doing woring in saving my plot.
My code:
Temp=[num2str(vaiable), 'Myplotnumber' ,num2str(n) ,'-dpng'];
saveas(gcf,Temp);
it save the figure always with Var1Myplotnumber2.png.fig
why put matlab .fig at the end?
Thank you?
채택된 답변
추가 답변 (3개)
Image Analyst
2020년 12월 20일
0 개 추천
Use exportgraphics() instead if you have R2020a or later.
댓글 수: 7
CSCh
2020년 12월 20일
CSCh
2020년 12월 20일
Image Analyst
2020년 12월 20일
How about if you do this:
g = gcf; % Or gca, whatever you want.
exportgraphics(g, Temp);
CSCh
2020년 12월 20일
Image Analyst
2020년 12월 20일
Try this code in a simple script or in the command window.
plot(1:11, 'b-', 'LineWidth', 2);
fullFileName = fullfile(pwd, 'Delete me.png');
exportgraphics(gcf, fullFileName);
Does it create the file? For me it does.
CSCh
2020년 12월 21일
Image Analyst
2020년 12월 21일
I don't know. You never showed me your exportgraphics() code that didn't work. You only showed it where it worked in the command window with a hard-coded filename string. Please post the non-working code from your m-file. Apparently it thinks your Temp did not have an extension on it. Are you sure Temp ends in '.png'?
Walter Roberson
2020년 12월 21일
Temp = {sprintf('%dMyplotnumber%d.png', vaiable, n),'-dpng'};
saveas(gcf, Temp{:})
Image Analyst
2021년 1월 5일
You can do
baseFileName = sprintf('%d Myplotnumber %d.png', variable, n); % Name without folder.
fullFileName = fullfile(yourFolder, baseFileName); % Prepend folder.
saveas(gcf, fullFileName);
카테고리
도움말 센터 및 File Exchange에서 Environment and Settings에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!