Syntax for ignoring Code Analyzer warning "This statement cannot be reached"
Mostrar comentarios más antiguos
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 comentarios
Alejandro Arrizabalaga
el 28 de Mayo de 2021
Editada: Alejandro Arrizabalaga
el 28 de Mayo de 2021
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
el 4 de Ag. de 2024
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.
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Matrix Indexing en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!