Reputation: 408
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
Upvotes: 0
Views: 835
Reputation: 1006
If you take a look at to the fopen
in Matlab documentation, you see that the second input argument in permission
(that is related to the own function NOT your OS):
fileID = fopen(filename)
fileID = fopen(filename,permission)
But you are passing the filename as a second parameters. you need to concatenate filepath and filename :
s1=fopen(strcat(folder, 'newText.txt'),'w');
Upvotes: 1