MATLAB: Printing multiple plots using -djpg to unique filenames


I am attempting to plot many figures. I am having trouble passing a variable name into the print statement. I need to create jpgs for each plot with a unique filename so I can later add the plots into a Word doc. I have trouble in general when attemtping to pass a variable into a function like below…
fname = strcat({'foo'}, num2str(kk));
print -djpeg fname;
fn = strcat({'foo'}, num2str(kk)) ;
print( gcf, '-djpeg', fn )

Best Answer

  • A frequently asked question...
    fn = strcat('foo', num2str(kk)); % No cell string!
    print(gcf, '-djpeg', fn);
    Why do yout use the curly braces in "{'foo'}"? If you need it for other reasons:
    fncell = strcat({'foo'}, num2str(kk));
    print(gcf, '-djpeg', fncell{1});