MATLAB: Why always fopen fails

fopentext file

in_file = fopen('name_of_file', 'wt');
It is my code i used to open a file .but it always return file identifier as -1.Why? Thank you for help.

Best Answer

Most likely you do not have write permissions in the current folder. Use a folder with write permissions and absolute file names:
in_file = fopen(fullfile(tempdir, 'name_of_file'), 'wt');