matlab判断文件是否损坏,检查 MATLAB 代码文件是否有问题
示例
以下示例使用了 lengthofline.m,它是帶有可改進代碼的 MATLAB 示例文件。您可以在 matlabroot/help/techdoc/matlab_env/examples 中可以找到該文件。如果要運行本例,請將 lengthofline.m 副本保存到 MATLAB 路徑下。
不帶任何選項的情況下對文件運行 mlint
要對示例文件 lengthofline.m 運行 mlint,請運行以下指令:
mlint('lengthofline')
MATLAB 在命令行窗口中顯示 lengthofline.m 的 M-Lint 消息:
L 22 (C 1-9): The value assigned here to variable 'nothandle' might never be used.
L 23 (C 12-15): NUMEL(x) is usually faster than PROD(SIZE(x)).
L 24 (C 5-11): 'notline' might be growing inside a loop. Consider preallocating for speed.
L 24 (C 44-49): Use STRCMPI(str1,str2) instead of using LOWER in a call to STRCMP.
L 28 (C 12-15): NUMEL(x) is usually faster than PROD(SIZE(x)).
L 34 (C 13-16): 'data' might be growing inside a loop. Consider preallocating for speed.
L 34 (C 24-31): Use dynamic fieldnames with structures instead of GETFIELD.
Type 'doc struct' for more information.
L 38 (C 29): Use || instead of | as the OR operator in (scalar) conditional statements.
L 39 (C 47): Use || instead of | as the OR operator in (scalar) conditional statements.
L 40 (C 47): Use || instead of | as the OR operator in (scalar) conditional statements.
L 42 (C 13-16): 'data' might be growing inside a loop. Consider preallocating for speed.
L 43 (C 13-15): 'dim' might be growing inside a loop. Consider preallocating for speed.
L 45 (C 13-15): 'dim' might be growing inside a loop.Consider preallocating for speed.
L 48 (C 52): There may be a parenthesis imbalance around here.
L 48 (C 53): There may be a parenthesis imbalance around here.
L 48 (C 54): There may be a parenthesis imbalance around here.
L 48 (C 55): There may be a parenthesis imbalance around here.
L 49 (C 17): Terminate statement with semicolon to suppress output (in functions).
L 49 (C 23): Use of brackets [] is unnecessary. Use parentheses to group, if needed.
有關這些消息及如何改善這些代碼的詳細信息,請參閱 MATLAB 桌面工具和開發環境文檔中的根據代碼分析器消息更改代碼。
以“顯示 ID”和“將結果返回到結構體”選項運行 mlint
要將結果存儲到結構體并包含消息 ID,請運行以下指令:
inform=mlint('lengthofline', '-id')
MATLAB 返回
inform =
19x1 struct array with fields:
message
line
column
id
要查看第一個消息的值,請運行以下指令:
inform(1)
MATLAB 顯示
ans =
message: 'The value assigned here to variable 'nothandle' might never be used.'
line: 22
column: [1 9]
id: 'NASGU'
此處,該消息表示,第 22 行上顯示的值從文件中的第 1 列延伸至第 9 列。NASGU 是消息 'The value assigned here to variable
'nothandle' might never be used.' 的 ID。
使用 mlint 顯示 McCabe 復雜度
要顯示 MATLAB 代碼文件的 McCabe 復雜度,需運行 mlint 并選擇 -cyc 選項,如下例所示(假設已將 lengthofline.m 保存到本地文件夾)。
mlint lengthofline.m -cyc
命令行窗口中的結果顯示了文件的 McCabe 復雜度,接著是 M-Lint 消息,如下所示:
L 1 (C 23-34): The McCabe complexity of 'lengthofline' is 12.
L 22 (C 1-9): The value assigned here to variable 'nothandle' might never be used.
L 23 (C 12-15): NUMEL(x) is usually faster than PROD(SIZE(x)).
L 24 (C 5-11): 'notline' might be growing inside a loop. Consider preallocating for speed.
L 24 (C 44-49): Use STRCMPI(str1,str2) instead of using UPPER/LOWER in a call to STRCMP.
L 28 (C 12-15): NUMEL(x) is usually faster than PROD(SIZE(x)).
L 34 (C 13-16): 'data' might be growing inside a loop. Consider preallocating for speed.
L 34 (C 24-31): Use dynamic fieldnames with structures instead of GETFIELD. Type 'doc struct'
for more information.
L 38 (C 29): Use || instead of | as the OR operator in (scalar) conditional statements.
L 39 (C 47): Use || instead of | as the OR operator in (scalar) conditional statements.
L 40 (C 47): Use || instead of | as the OR operator in (scalar) conditional statements.
L 42 (C 13-16): 'data' might be growing inside a loop. Consider preallocating for speed.
L 43 (C 13-15): 'dim' might be growing inside a loop. Consider preallocating for speed.
L 45 (C 13-15): 'dim' might be growing inside a loop. Consider preallocating for speed.
L 48 (C 52): There may be a parenthesis imbalance around here.
L 48 (C 53): There may be a parenthesis imbalance around here.
L 48 (C 54): There may be a parenthesis imbalance around here.
L 48 (C 55): There may be a parenthesis imbalance around here.
L 49 (C 17): Terminate statement with semicolon to suppress output (in functions).
L 49 (C 23): Use of brackets [] is unnecessary. Use parentheses to group, if needed.
總結
以上是生活随笔為你收集整理的matlab判断文件是否损坏,检查 MATLAB 代码文件是否有问题的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 200 年后,人们终于知道了贝多芬的神秘
- 下一篇: 4K 3D高帧率重制!卡梅隆《泰坦尼克号