Syntax for ignoring Code Analyzer warning "This statement cannot be reached"
古いコメントを表示
I'm aware of a few warning ignore comment syntaxes, such as
%#ok<AGROW>
for variables that change size on each loop iteration. But I haven't been able to find one for if branch errors, such as in
flag = 0;
if flag
foo
end
In fact, it's been stated elsewhere that no central list of warning IDs exists, which frankly is inexcusable. Where is a list of common warning IDs and their ignore comments?
2 件のコメント
Alejandro Arrizabalaga
2021 年 5 月 28 日
編集済み: Alejandro Arrizabalaga
2021 年 5 月 28 日
I used to suffer a lot from this issue. The solution is very simple but also weird, which is just to do:
flag = 0;
if flag ~= 0
foo
end
I would have expected MATLAB to check flag to be true (1) or false (0) without having to explicitly write flag ~= 0. But it seems that MATLAB Code Analyzer complains if one does not do this.
Ron Fredericks
2024 年 8 月 4 日
Alejandro's suggested solution is the best for my code use - as even if there is an "else" clause in the if statement there is no useless warning produced.
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Matrix Indexing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!