Saving a figure as a png with a specific name from predefined variable

13 views (last 30 days)
I would like to save a figure as a png with the name as a value that I had already predefined in the code. The code below is not calling that value. My variable that I would like to use as the name of the png is defined as plottitle.
I keep getting an error that says invalid filename.
plottitle is my variable
saveas(gcf,plottitle.bmp)
Output: Error using saveas (line 96)
Invalid filename.
  1 Comment
Jan
Jan on 22 Jan 2019
"Invaluid filename" is a surprising message. If plottitle is a string, which contains the name of the file, plottitle.bmp is interpreted as the access of the field bmp of a struct. Then the error message should be different.
It is recommended to post running examples. As soon as you show how plottitle is defined, the actual problem would be clear.

Sign in to comment.

Accepted Answer

Jan
Jan on 22 Jan 2019
Edited: Jan on 22 Jan 2019
With some guessing:
saveas(gcf, [plottitle, '.bmp'])
  1 Comment
Jeremy Flint
Jeremy Flint on 22 Jan 2019
When I input that code I get the following error
Error using horzcat
Dimensions of matrices being concatenated are not consistent.
Error in Uniform_Plots (line 61)
saveas(gcf, [plottitle, '.bmp'])
However the following code does work:
saveas(gcf,p.Title{1,1},'bmp')
Thank you

Sign in to comment.

More Answers (0)

Categories

Find more on Printing and Saving in Help Center and File Exchange

Products


Release

R2017b

Community Treasure Hunt

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

Start Hunting!