MATLAB: Input String Variable to SaveAs Command

plotsaveasstringvariable

I'm trying to write the SaveAs command to save a plot. Upstream of the command, I'm trying to create a string parameter that's comprised of a variable from the calculations. Below is the snippet of code that I'm working with. I'd like to capture the value of the "d" parameter in the SaveAs filename. I figured I might be able to do this by first writing a string variable having the "d" parameter within. Then I try to reference that string variable in the SaveAs command. It doesn't seem to work though. Is there another way to do this?
d=100E-6;
str_saveas="HW_2_%d_micron_particle";
z=d*10^6;
str_saveas=sprintf(str_saveas,z)
saveas(figure(1),'str_saveas','fig');
Thanks in advance, M Ridzon

Best Answer

d = 100E-6;
str_saveas = 'HW_2_%d_micron_particle.fig';
z = d*10^6;
str_saveas = sprintf(str_saveas, round(z));
saveas(figure(1), str_saveas, 'fig');
saveas(figure(1), str_saveas, 'fig');