MATLAB: Saving file in different directory than than loading dir.

efficiencyloadMATLABsave

I would like to save files dirrectly after some operations in different directory than I loading directory. Is there any way to do in efficiently.
My code :
cd('C:\Users\Jonasz\Documents\Studia_Biotechnologia\_Projekt\N');
save(Names,'newy');
cd(PathName);
where PathName – loading directory.
I think is without sense to open each time other directory and than open second one each time in a for loop ( loop is very long , n is 10 thousand) Is there any way to put it inside save command or something else more efficient.

Best Answer

There's no need to 'cd' at all...just build a fully qualified file name
savdir = 'C:\Users\Jonasz\Documents\Studia_Biotechnologia\_Projekt\N';
save(fullfile(savdir,Names),'newy');
doc fullfile % for details
--