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

2 ビュー (過去 30 日間)
raghavendra kandukuri
raghavendra kandukuri 2018 年 8 月 24 日
回答済み: Image Analyst 2018 年 8 月 25 日
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

採用された回答

Stephen23
Stephen23 2018 年 8 月 24 日
編集済み: Stephen23 2018 年 8 月 24 日
Just use fullfile like this, each time you call any function that reads/writes files:
dlmwrite(fullfile(SaveDir,'PRM.txt') ,...)
  6 件のコメント
raghavendra kandukuri
raghavendra kandukuri 2018 年 8 月 24 日
編集済み: Walter Roberson 2018 年 8 月 24 日
Now it works:
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...');
end
dlmwrite(fullfile(SaveDir,'PRM.txt'),m1,'delimiter','\t','-append','newline','pc');
dlmwrite(fullfile(SaveDir,'PRM.txt'),ThrTbl,'delimiter','\t','-append','newline','pc');
Stephen23
Stephen23 2018 年 8 月 25 日
@raghavendra kandukuri: remember to accept the answer that helped you to resolve your original question!

サインインしてコメントする。

その他の回答 (1 件)

Image Analyst
Image Analyst 2018 年 8 月 25 日
Try this:
% Get the name of the file that the user wants to save.
% Note, if you're saving an image you can use imsave() instead of uiputfile().
startingFolder = userpath % Or "pwd" or wherever you want.
defaultFileName = fullfile(startingFolder, 'PRM.txt');
[baseFileName, folder] = uiputfile(defaultFileName, 'Specify a file');
if baseFileName == 0
% User clicked the Cancel button.
return;
end
fullFileName = fullfile(folder, baseFileName)
dlmwrite(fullFileName, .......etc.

カテゴリ

Help Center および File ExchangeSpreadsheets についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by