Permission to write into text file

Hello
I got the following error below:
Permission denied : I am unable to open file mojo.txt
find the code below
function savechangeptsButtonPushed(app, event)
writematrix(app.UITable.Data, 'mojo.txt')
end
end
What do I do to solve the issue
Thanks in advance

6 Comments

What is the current folder during that call? Are you sure you have write access in the first place?
Yes I have write access Rik and I do not know why am getting the error
Tino - try creating and writing the file to a different folder (one where you have read and write permissions).
Use debugger and ensure you're where you think you are when the callback executes...it appears there are no returned optional diagnostic messages available from writematrix to give any additional klews like what can help from fopen and friends.
In fact, using fopen instead with the optional error return might be of interest/benefit.
Another possibility is that the file is already opened (with write access) by some other program. In any case, matlab just asks the OS to open the file for write access. It's the OS that tells matlab it's not possible. Nothing matlab can do anything about.
"...Nothing matlab can do anything about."
Other than trap the OS error and report it which may (or may not) be more informative to the user than just "I can't do that!" and die.

Sign in to comment.

 Accepted Answer

Jan
Jan on 9 Jul 2019
Edited: Jan on 9 Jul 2019
Do not use 'mojo.txt' as file name without a path. Remember, that any GUI or timer callback could call cd to change the current folder unexpectedly.
function savechangeptsButtonPushed(app, event)
folder = tempdir; % Insert your preferred folder here
file = fullfile(folder, 'mojo.txt');
try
writematrix(app.UITable.Data, file);
catch ME
error(['Cannot create file: %s', newline, '%s'], file, ME.message);
end
end

2 Comments

Hi Jan
Thanks for your response
I am not getting any error but the data is not written to the text file
How do I solve this
Thanks in advance
Located the files lol

Sign in to comment.

More Answers (0)

Categories

Products

Release

R2019a

Tags

Asked:

on 9 Jul 2019

Commented:

on 9 Jul 2019

Community Treasure Hunt

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

Start Hunting!