MATLAB: How to create image file with two variable values as the filename

file_namefilenameimwritematabMATLABsprintf

Please help.
I need to write image with variable values as a filename. I can use this code for one value:
variance = 1;
tempname = 'result/speckle_%d_proposed.png';
d = variance;
filename = sprintf(tempnameg,d);
imwrite(image,filename,'png');
But what if I want to write image with two values as a filename?
len = 1;
theta = 0;
I need the filename to be something like this:
result/mblur_(len)_(theta)_proposed.png
or
result/mblur_1_0_proposed.png
I really appreciate any help on this. Thanks in advance!

Best Answer

The best way to do this is to use sprintf, just like you were doing for one variable:
fmt = 'result/mblur_%d_%d_proposed.png';
fnm = sprintf(fmt,len,theta);
imwrite(image,fnm,'png');
Do not use strcat, horzcat or the like. Note also that you can create full file paths by using fullfile, should you need to do so.