MATLAB: How to define a path in saveas command

pathsaveas

Hey Matlab users,
I've got a problem in defining a path for saveas command. When i want to save my Figure, the file is directly been saved in a path that is already on top of the command window in front of the "Current Folder". I tried to change the address by fname:
fname = 'D:\path1\path2';
saveas(gca,filename,'jpeg');
But it didn't work!!!
I very much appreciate your hint 🙂 Mehdi

Best Answer

You have to consider the variable fname in the call of saveas:
fname = 'D:\path1\path2';
saveas(gca, fullfile(fname, filename), 'jpeg');
I assume "fpath" would be more meaningful than "fname".
Related Question