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 Center および File ExchangeGet Started with MATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by