m file code sometimes loss a "end" and corruput the file on hard disc.

조회 수: 1 (최근 30일)
raym
raym 2022년 3월 23일
댓글: Rik 2022년 3월 23일
I encountered some very rare error (~1 occurance/year).
The error is that when I run matlab project/functions, very rarely the code is corrupted, one time it is a variable name that was changed at somewhere which cause an error(The old variable name is updated, and run for many times OK, then suddenly error take place one day saying that a variable is not defined), the other time is the lossing of a "end" statement in middle, so the code jump to the FUNCTION END and cause error of no argout.
This is strange since I have not edit this code for many months but still using it everyday. But it just happened just now.
I thought it might be caused by too heavy usage of my xps13 laptop for past 7 years. I used Matlab too heavily to automate my enumourous works and my laptop seems to be at the final stage of its life.
Not sure if someone else also encountered this kind of problem.

채택된 답변

Jan
Jan 2022년 3월 23일
편집: Jan 2022년 3월 23일
It is extremely unlikely, that the 3 characters "end" vanish inside a text file, while the rest of the computer runs without a crash. Such behaviour would be a sign of pure magic.
This effect happens frequently and you find many similar questions. In all (!) cases, there have been deterministiv reasons, which the user was not aware of. Of course, this does not allow to prove, that this is true in your case alos, but it is a very strong evidence.
Compare the changed files with your backups. Check, when these files have been changed or if you have several files with the same name and are running another version, because the current directory is the folder, which contains the other M file.
If the 3 characters "end" would be changed to some strange uni-code characters, a failing SSD or hard disk would be more plausible. But a clean vanishing is too unlikely.
Use a chkdsk (assuming you work with Windows) and a tool like CrystalDiskInfo to check the integrity of the disk. But have in mind, that there is another important source of problems, which you did not consider yet. A version history, which contains all changes of each file, is required for a reliable programming.
  댓글 수: 1
raym
raym 2022년 3월 23일
Ah Yes, I think I got the reason for the missing end:
When I update code months ago, I inserted a if-end statement but missed a end in the root level, so the FUNCTION END was used instead.
Then all the running later meet the condition, thus I cannot find this defect.
Today I use another condition thus it does not meed, then jump to end with no argout.
The first scenario should also be the similar cause: The code was not fully tested but can work in certain condition for many time, until the condition was not met.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by