MATLAB: How to give an option to user of where to save the generated file

browsedlmwriteguideuigetdir

How to give an option to user of where to save the generated file, right now it is storing those files where .m files are there, but i want to give user the flexibility of storing those files where ever they want, i have tried the following code and its not working. It is opening the that browse location window but the output is not storing there, it still stores at, where .m files are.
downloadsFolder = strcat('C:\Users\',getenv('username'),'\Downloads');
SaveDir = uigetdir(downloadsFolder,'Select folder to save newly created Excel files to…');
while SaveDir == 0
SaveDir = uigetdir(downloadsFolder,'Select folder to save newly created Excel files to…');
dlmwrite('PRM.txt',m1,'delimiter','\t','-append','newline','pc');
dlmwrite('PRM.txt',ThrTbl,'delimiter','\t','-append','newline','pc');
end

Best Answer

Just use fullfile like this, each time you call any function that reads/writes files:
dlmwrite(fullfile(SaveDir,'PRM.txt') ,...)