Permission to write into text file

12 ビュー (過去 30 日間)
Tino
Tino 2019 年 7 月 9 日
コメント済み: Tino 2019 年 7 月 9 日
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 件のコメント
Guillaume
Guillaume 2019 年 7 月 9 日
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.
dpb
dpb 2019 年 7 月 9 日
"...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.

サインインしてコメントする。

採用された回答

Jan
Jan 2019 年 7 月 9 日
編集済み: Jan 2019 年 7 月 9 日
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 件のコメント
Tino
Tino 2019 年 7 月 9 日
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
Tino
Tino 2019 年 7 月 9 日
Located the files lol

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeStartup and Shutdown についてさらに検索

タグ

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by