[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
## Re: Warning : Matlab-style short-circuit operation performed for operato

**From**: |
siko1056 |

**Subject**: |
Re: Warning : Matlab-style short-circuit operation performed for operator | |

**Date**: |
Tue, 25 Oct 2016 06:33:36 -0700 (PDT) |

There might be some error in your if-statement-logic. For example
nr = nc = 1000;
A = B = zeros (nr, nc);
i_nouveau = 1001;
j_nouveau = 1001;
i = 1001;
j = 1001;
if i_nouveau >=1 | i_nouveau<=nr & j_nouveau>=1 | j_nouveau<=nc;
if i >=1 | i<=nr & j>=1 | j<=nc;
B(i_nouveau,j_nouveau)=A(i,j);
endif
endif
All indices exceed the matrix dimensions of A and B, but the statement
between the two if-statements will be executed. Now it depends what you are
willing to check with your if-statements. If you want to check all indices
to be valid, it should be
if ((i_nouveau >=1) && (i_nouveau <= nr) && (j_nouveau >= 1) && (j_nouveau
<= nc))
if ((i >=1) && (i <= nr) && (j >= 1) && (j <= nc))
B(i_nouveau,j_nouveau) = A(i,j);
endif
endif
because all constraints on the indices have to be fulfilled (logical &&).
But this depends on you purpose. For more explanation on the operators, read
[1] and [2]
HTH,
Kai
[1]:
https://www.gnu.org/software/octave/doc/v4.0.3/Short_002dcircuit-Boolean-Operators.html
[2]:
https://www.gnu.org/software/octave/doc/v4.0.3/Element_002dby_002delement-Boolean-Operators.html
--
View this message in context:
http://octave.1599824.n4.nabble.com/Warning-Matlab-style-short-circuit-operation-performed-for-operator-tp4680361p4680364.html
Sent from the Octave - General mailing list archive at Nabble.com.