MATLAB writing text file “invalid permission” in UBUNTU

5 views (last 30 days)
I'm trying to use MATLAB to write a text file in a folder other than "current folder" in UBUNTU. This folder is located in home directory so there would be no permission problem. I'm using the code that is shown below:
folder = '~/newFolder';
s1=fopen(folder,'newText.txt','w');
fprintf(s1,'hi')
fclose(s1);
But when I run the program, it shows invalid permission error. It would worth to mention that I've no problem when I try to write the text in the current folder. I also tried chmod 0777 -R ~/newFolder to modify the permission with no success. What shall I do?
Thanks

Accepted Answer

per isakson
per isakson on 20 May 2018
Edited: per isakson on 20 May 2018
  • permission is the second argument.
  • filename is the full file specifier
Thus, replace
folder,'newText.txt'
by
fullfile( folder, 'newText.txt' )

More Answers (0)

Categories

Find more on Data Import and Export in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!