Saving file at different directory

64 ビュー (過去 30 日間)
AStro
AStro 2021 年 9 月 22 日
コメント済み: Image Analyst 2021 年 9 月 22 日
Hi,
I am having trouble changing the directory where my file should be saved. I use the command:
[file, pathdir] = uiputfile('FileNAME.txt');
then I choose a new directory. However, each time my file is saved in the current folder (where the .m script is saved).
Can anyone explain why this is and how to solve it?

採用された回答

Stephen23
Stephen23 2021 年 9 月 22 日
編集済み: Stephen23 2021 年 9 月 22 日
You need to use FULLFILE to include the path in the filename, e.g.:
[F,P] = uiputfile('FileNAME.txt');
fnm = fullfile(P,F); % <------ you need this!
and then use its output with whatever command you are using to save your data, e.g.:
writematrix(..,fnm,..)
  2 件のコメント
AStro
AStro 2021 年 9 月 22 日
Thank you :-)
Image Analyst
Image Analyst 2021 年 9 月 22 日
I'd suggest you use more descriptive variable names
[baseFileName, outputFolder] = uiputfile('FileNAME.txt');
fullFileName = fullfile(outputFolder, baseFileName); % <------ You need this!
but it should work, so can you "Accept this answer" to award Stephen his reputation points? Thanks in advance.

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by