matlab判断文件是否损坏,检查 MATLAB 代码文件是否有问题
示例
以下示例使用了 lengthofline.m,它是帶有可改進(jìn)代碼的 MATLAB 示例文件。您可以在 matlabroot/help/techdoc/matlab_env/examples 中可以找到該文件。如果要運(yùn)行本例,請(qǐng)將 lengthofline.m 副本保存到 MATLAB 路徑下。
不帶任何選項(xiàng)的情況下對(duì)文件運(yùn)行 mlint
要對(duì)示例文件 lengthofline.m 運(yùn)行 mlint,請(qǐng)運(yùn)行以下指令:
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.
有關(guān)這些消息及如何改善這些代碼的詳細(xì)信息,請(qǐng)參閱 MATLAB 桌面工具和開(kāi)發(fā)環(huán)境文檔中的根據(jù)代碼分析器消息更改代碼。
以“顯示 ID”和“將結(jié)果返回到結(jié)構(gòu)體”選項(xiàng)運(yùn)行 mlint
要將結(jié)果存儲(chǔ)到結(jié)構(gòu)體并包含消息 ID,請(qǐng)運(yùn)行以下指令:
inform=mlint('lengthofline', '-id')
MATLAB 返回
inform =
19x1 struct array with fields:
message
line
column
id
要查看第一個(gè)消息的值,請(qǐng)運(yùn)行以下指令:
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 復(fù)雜度
要顯示 MATLAB 代碼文件的 McCabe 復(fù)雜度,需運(yùn)行 mlint 并選擇 -cyc 選項(xiàng),如下例所示(假設(shè)已將 lengthofline.m 保存到本地文件夾)。
mlint lengthofline.m -cyc
命令行窗口中的結(jié)果顯示了文件的 McCabe 復(fù)雜度,接著是 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.
總結(jié)
以上是生活随笔為你收集整理的matlab判断文件是否损坏,检查 MATLAB 代码文件是否有问题的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 200 年后,人们终于知道了贝多芬的神秘
- 下一篇: 二维碰撞检测matlab,二维平面内的碰