Reputation: 109
I have no idea how to save file when the name contains variables.
A = figure();
% some code
fileName = sprintf('sig1=%d mu1 =%d p1=%.2f sig2 = %d mu2 = %d p2 = %.2f', ...
sigma1, mi1, double(p1), sigma2, mi2, double(p2));
print(A, fileName, '-dpng');
Upvotes: 0
Views: 1918
Reputation: 391
I got this to work:
A = figure;
plot(1:10,sin(pi*(1:10)./4))
fileName = sprintf('sig1=%d mu1 =%d p1=%.2f sig2 = %d mu2 = %d p2 = %.2f.png', ...
1, 2, double(3), 4, 5, double(6));
print(A, fileName, '-dpng');
The png file opened just fine. When you want the png file name to have variables in it, this is the correct approach. You can set a lot more figure specifications by using the figure handle ("A", in this case) and the set(A,...)
function. Look at the matlab documentation for using the set(A,...)
function and gcf
. If you type get(A)
, you will see a list of properties that you can set before you save your figure.
Please let me know if this helps.
Upvotes: 1