I can't delete the file obtained with matlab

18 次查看(过去 30 天)
.....
writecell(bu,hhh,'Delimiter',' ');
when I kill writecell process (using ctrl+c) in matlab i receive this error and if i try to delete file
i receive this error:
The operation could not be completed because the file is open in matlab R2024a

采纳的回答

dpb
dpb 2024-7-21
移动:dpb 2024-7-21
You'll have to exit and restart MATLAB, then...
I've never had MATLAB keep the file handle open; Excel if using ActiveX and crash, yes, but not MATLAB.
Somehow the error handler/cleanup function isn't managing to close the open file and let the OS know. That is worthy of a bug report, but it is probably not reliably reproducible.
But, Ctrl-C while writing a file is risky behavior although ideally it should be able to be handled...
  3 个评论
Luca Re
Luca Re 2024-7-21
I can create a button with "Break" to press to avoid the ctrl+c but how should I code it?
dpb
dpb 2024-7-21
There is no provided facility for that; you would have to stuff the Ctrl-C into the keyboard buffer and drawnow to update callbacks (and not sure that would work). Such things should be avoided.
The only clean way to do something of that sort would be to not dispatch the writecell call with the entire file but in a loop and check for user cancellation at the end of each pass through the loop. This would obviously add even more overhead and have a latency period (MsgBox("Please Standby")) until the current call completes and can check the flag to terminate.
What and how large a file are you writing such that it is wanted to cancel the operation? If the user asked to write the file, it would seem a fairly rare event to then subsequently want to cancel?
I think it may be worth a support request to Mathworks about the open file handle from the command line to see if they think that is expected behavior or not despite the poor practice from user. I would think the registered cleanup functions should be able to deal with it cleanly, but it's worth asking about. As said, I've not seen the symptom, but I've not done the exercise that often and don't have that release of MATLAB installed.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Introduction to Installation and Licensing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by