Is equality == available in Matlab 2017 ?

2 次查看(过去 30 天)
JGUIS
JGUIS 2018-8-21
Hello, I use Matlab 2017 R2017b and I would like to establish an equality of two vectors of this kind :
if true
A = [1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4 4];
B = [1 1 1 2 2 2 3 3 3 4 4 4];
A == B
end
I would like to obtain a vector as result but ''=='' is not recognize. Is equality not exist in Matlab version 2017? If yes, how can I exactly replace that to have the same result that furnished ''==''
  1 个评论
Stephen23
Stephen23 2018-8-21
编辑:Stephen23 2018-8-21
"Is equality not exist in Matlab version 2017"
== exists for all MATLAB versions since atleast the first PC version of 1985.
"I would like to obtain a vector as result but ''=='' is not recognize."
You don't define what "equality" means for vectors of two different sizes. What size do you expect the output vector to be?

请先登录,再进行评论。

回答(3 个)

Geoff Hayes
Geoff Hayes 2018-8-21
JGUIS - equality does exist in MATLAB, see Determine equality for details. With your above example, you are probably observing the
Error using ==
Matrix dimensions must agree.
error because your two arrays are of different dimensions and so cannot possibly be equal.
I suspect that you are looking for a different type of equality (perhaps they have the same elements, same order, etc.). Please clarify.
  2 个评论
ARN
ARN 2018-8-21
Matrix dimensions should be equal to use this operator and i am using "==" in Matlab 2017 and its working. Make sure the two vectors/matrices you are comparing must be of same size. You can also see isequal if it fits in your code
JGUI
JGUI 2018-8-21
Thank a lot for your answer, In fact, it was an error of inattention about the size of the matrix I try this and I obtain what i was looking for : a binary vector 1x19
if true
W = [1 1 1 1 1 2 2 2 2 3 3 3 3 3 4 4 4 4 4];
for i = 1 : 4
wx_ind = W == i;
end

请先登录,再进行评论。


Steven Lord
Steven Lord 2018-8-21
I'm fairly certain the == operator has been part of MATLAB since Cleve's original version. [If not, it was introduced not long after that.] It is certainly present in release R2017b. The problem you receive is not that == is undefined, it's that you're trying to compare arrays of different sizes.
If you wanted a matrix as a result, with a number of rows equal to the number of elements in A and a number of columns equal to the number of elements in B, that's possible thanks to implicit expansion.
A = [1 2 3 4];
B = [3 1];
A.' == B
If you wanted to know if the elements in A are present in B or vice versa, take a look at the ismember function.
If neither of those are what you want, please explain in more detail what you expect the result of A == B to be (what size should it be?) and how you would compute it by hand and we may be able to help you determine how to compute it in MATLAB.

Chad Greene
Chad Greene 2018-8-21
I think you want isequal.

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

产品


版本

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by