Adding parameter to file name string when saving a figure as a jpeg

조회 수: 42 (최근 30일)
Luke
Luke 2014년 9월 10일
답변: Muaz Khan 2017년 3월 2일
I'm running code on different point clouds (each with their own name) to produce graphs, and the name of the point cloud is an input parameter in my function. I want the graph produce to be switched from a fig to a jpg and for the name of the file to include the point cloud name. Currently the code is running and saving as a jpg and overwriting the current jpg each time (meaning i have to go in and change the filename before running the code again). I have set the file name to be a string with the variable included to then save the figure as a jpg, but this doesn't seem to work. I've also used saveas(plt, sprintf(''),''jpg) where plt is what ive set my plot to, and this doesnt work either.
Cheers!

답변 (2개)

Iain
Iain 2014년 9월 10일
filename = ['Point cloud ' num2str(5) '.jpg'];
saveas(1,filename)
  댓글 수: 2
Luke
Luke 2014년 9월 10일
Cheers for the reply, what is the 'num2str(5)'?
Joseph Cheng
Joseph Cheng 2014년 9월 10일
편집: Joseph Cheng 2014년 9월 10일
Iain gave an example of building/concatenating the filename string first then using it in the saveas. Since your parameters are probably numbers Iain is converting the number of a said parameter to a string such that there would be no type mismatch.
So if you look at the function help (ie type in help num2str) you'll see what it does.

댓글을 달려면 로그인하십시오.


Muaz Khan
Muaz Khan 2017년 3월 2일
Thank you. It helped me :-)

카테고리

Help CenterFile Exchange에서 Printing and Saving에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by