Saving file at different directory

조회 수: 44 (최근 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 CenterFile Exchange에서 Variables에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by