Error saving file: Cannot create '<filename>.mat' because '<fullpath>' does not exist.

조회 수: 54 (최근 30일)
Jessica
Jessica 2013년 5월 7일
편집: Stephen23 2020년 5월 22일
Hello,
I have tried every variation I can think of as well as Googled and cannot come up with a solution. I'm baffled as to why this is happening. Here's what's happening: I read in some files from my external hard drive, run them through my code, and then try to save the output back to my external hard drive. I have an absolute path "/Volumes/TOSHIBA EXT/...". It gets the input files just fine, but then it fails when I use the "save" function.
Specs: running R2011b on Mac OS X 10.6.8
Here's a bit of my code:
path_to_project_data = '/Volumes/TOSHIBA'' EXT''/preseis/Documents/Project'' Data''/' ;
matlab_save = '/Volumes/TOSHIBA'''' EXT''''/preseis/Documents/Project'''' Data''''/' ;
path_to_files2_3 = fullfile(path_to_project_data,'CyberShake/FFMs/FengABFSet/RuptureGenerator2_3/') ;
matlab_save2_3 = fullfile(matlab_save,'CyberShake/FFMs/FengABFSet/RuptureGenerator2_3/') ;
<do some stuff to create a structure variable "FFM">
name = FFM.event_id ; % a string event name identifier
eval(['save ''' matlab_save2_3 'MatlabFiles/FFM/' name '.mat'' FFM'])
----------
Output:
Error using save
Cannot create 'C218_0s0000h0000.mat' because '/Volumes/TOSHIBA' EXT'/preseis/Documents/Project'
Data'/CyberShake/FFMs/FengABFSet/RuptureGenerator2_3/MatlabFiles/FFM' does not exist.
This code does not work and I have tried the following variations:
String concatenation without using the "fullfile' function:
path_to_files2_3 = [path_to_project_data 'CyberShake/FFMs/FengABFSet/RuptureGenerator2_3/'] ;
Changing the save command:
eval(['save ' path_to_files2_3 'MatlabFiles/FFM/' name '.mat FFM'])
eval(['save ''' path_to_files2_3 'MatlabFiles/FFM/' name '.mat'' FFM'])
save([path_to_files2_3 'MatlabFiles/FFM/' name '.mat'],'FFM')
**as well as the above variations using matlab_save2_3 in place of path_to_files2_3
Changing the path_to_project_data variable:
path_to_project_data = '/Volumes/TOSHIBA EXT/preseis/Documents/Project Data/' ;
path_to_project_data = '/Volumes/TOSHIBA\ EXT/preseis/Documents/Project\ Data/' ;
path_to_project_data = '/Volumes/TOSHIBA'''' EXT''''/preseis/Documents/Project'''' Data''''/' ;
**as well as the above variations using matlab_save and every possible combination of the two together
I even typed in the command window:
save '/Volumes/..../<filename>.mat' FFM
*using* tabs to fill in the save string to make sure I wasn't mistyping anything...it still failed with the same message. I tried loading an existing file from the same directory and the "load" function works just file with the full file path I gave it. I am so confused and at my wits end.
Can someone please help me with this! Why won't "save" work, but "load" and my "system" calls work with these full file paths I've given??? Please and thank you!
  댓글 수: 4
Ramkumar
Ramkumar 2013년 9월 28일
Another probable reason is that you do not have 'write' access to the location where you want to write the file. This has happened to me before. The code which ran perfectly in my laptop and was able to save the file was not able to do so in my office computer. It gave me the same error you have mentioned. Then I realized that I was saving the file to a location where I did not have permission to save.
Check for this also..
Ram
Stephen23
Stephen23 2015년 3월 31일
편집: Stephen23 2020년 5월 22일
Why on earth are you using eval just to call save ? Do NOT do this !
That practically guarantees that you will have buggy undebuggable code.

댓글을 달려면 로그인하십시오.

답변 (3개)

Walter Roberson
Walter Roberson 2013년 9월 29일
Why the heck are you doing this at all, with eval(), instead of calling save() as a function?
A_path = 'some string';
save(A_path, 'the_variable');
If you need EXT and whatever to be substituted in dynamically, then use sprintf to construct the file name:
series_name = 'CyberShake/FFMs/FengABFSet/RuptureGenerator2_3';
experiment_name = 'XY034'
A_path = sprintf('/your/base/directory/%s/%s.mat', series_name, experiment_name);
save(A_path, 'the_variable');

Siluveru Kiran Kumar
Siluveru Kiran Kumar 2018년 4월 10일
If you are using ubuntu os run matlab with root mode i.e in the terminal sudo ./matlab

Arjun Sahdev
Arjun Sahdev 2018년 12월 6일
I had the same problem while I was saving a string array in .mat format. The problem was that you have to give the filename accesible within the current operating directory. The operating directory is where your code is saved. Then moment I did that it worked. Another reason might be that you are speciying the path incorrectly.

카테고리

Help CenterFile Exchange에서 Environment and Settings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by