is it possible to append if file doesnt already exist?

13 views (last 30 days)
is it possible that matlab creates the file if it doesnt exist in append mode? i run a program which produces gb's of data. so i keep saving the variables in a file in steps and clear the variables.so i use append. but it says "Unable to write file samp.mat: No such file or directory." i use save function.

Accepted Answer

Jan
Jan on 20 Dec 2011
The save command needs an existing file for appending. This can be caught easily:
if exist(FileName, 'file')
save(FileName, '-append');
else
save(FileName);
end
It could be much faster to write a binary file using FPRINTF.
  3 Comments
Ali
Ali on 4 Feb 2015
I think Mathworks should improve save function: if the file does not exist, matlab automatically creates it; if it exist, matlab append to it.
Zhe Li
Zhe Li on 21 Aug 2019
I agree with Ali. The behavior is different from how native "write" methods in most languages work.

Sign in to comment.

More Answers (0)

Categories

Find more on Environment and Settings in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!