MATLAB: Print figure to a specific path

MATLABprint figure directory

Hi,
I'm using MATLAB version R2016a on a Mac and I'm having trouble printing a figure to a different directory than the current one. Could someone please help me fix my mistake? I have tried the following code:
print('Ult_Stress_vs_Temp','-dpng','/Users/Tim/Documents/2-Grad-School/Research/Technical-Paper/Latex/Figures/')
This is the error message I receive:
Error using inputcheck (line 40)
Multiple inputs that look like file names: 'Ult_Stress_vs_Temp' and
'/Users/Tim/Documents/2-Grad-School/Research/Technical-Paper/Latex/Figures/'.
Error in print (line 41)
[pj, devices, options ] = inputcheck( pj, inputargs{:} );
Error in ult_stress_temp_plot (line 47)
print('Ult_Stress_vs_Temp','-dpng','/Users/Tim/Documents/2-Grad-School/Research/Technical-Paper/Latex/Figures/')
>>

Best Answer

You need to pass a handle to the figure you wish to print. The parameter 'Ult_Stress_vs_Temp' is, I assume, maybe the title of the plot? This will not work. Ideally you will have created a handle to the figure when you created it (hfig = figure; plot(x,y), or similar).
You then print as: print(hfig, '-dpng', '/Users/Tim/Documents/2-Grad-School/Research/Technical-Paper/Latex/Figures/Ult_Stress_vs_Temp.png'). Note that you need to provide the filename, not just a folder location.
Related Question