What is difference between isequal and == in comparing two vectors

40 Ansichten (letzte 30 Tage)
Hansori Chang
Hansori Chang am 13 Sep. 2019
Kommentiert: Stephen23 am 15 Sep. 2019
Two vectors that have the same values and same length.
However, I want to know what are the difference between == and isequal(A,B), comparing two vectors

Antworten (1)

the cyclist
the cyclist am 13 Sep. 2019
Bearbeitet: the cyclist am 13 Sep. 2019
isequal will return a single logical value, indicating whether or not the two vectors are identical.
== will give a vector with element-by-element comparison.
>> x = [1 2 3 4];
>> y = [1 2 3 5];
>> x == y
ans =
1×4 logical array
1 1 1 0
>> isequal(x,y)
ans =
logical
0
Also, isequal will work on unequal-sized vectors, and == will give an error (because the mismatch in number of elements prevents the element-by-element comparison).
  11 Kommentare
the cyclist
the cyclist am 14 Sep. 2019
Bearbeitet: the cyclist am 14 Sep. 2019
(I was replying to Stephen, not you Bruno.)
I agree that the non-transivitity is pretty surprising, and could be documented more clearly. Your latest set of comparisons are really a surprise to me, especially that
isequal( {'frog'} , "frog" )
is true.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Characters and Strings finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by