0

I am trying to save some data from current workspace in Matlab to a different folder. I tried using

 save('c:\stp\vtp\train.txt','data','-ASCII');

where data is a double matrix. It gives me error message

??? Error using ==> save
Unable to write file c:\stp\vtp\train.txt: No such file
or directory.

I tried using fullfile syntax, even then it is the same case. My current working folder is in different path.

1
  • 2
    Perhaps the directory does not exist? Commented Mar 19, 2013 at 21:32

1 Answer 1

3

You probably need to run mkdir first. For example:

%Some data to save
x = 1;

%Try to save it in a deep, non-existent directory
save(fullfile(tempdir,'sub1','sub2','sub3','sub4','data.mat'),'x');  
%    This will probably recreate your error

%To fix, first create the directory
mkdir(fullfile(tempdir,'sub1','sub2','sub3','sub4'))
%Now save works
save(fullfile(tempdir,'sub1','sub2','sub3','sub4','data.mat'),'x')  %No error
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the response. I figured that out. I tried to misspell the path I am trying to save in. That caused the problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.