Is equality == available in Matlab 2017 ?
9 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaire
Stephen23
le 21 Août 2018
Modifié(e) : Stephen23
le 21 Août 2018
"Is equality not exist in Matlab version 2017"
"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?
Réponses (3)
Geoff Hayes
le 21 Août 2018
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 commentaires
ARN
le 21 Août 2018
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
le 21 Août 2018
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
le 21 Août 2018
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.
0 commentaires
Voir également
Catégories
En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!