compare two matrices

363 ビュー (過去 30 日間)
Ellen
Ellen 2011 年 5 月 23 日
回答済み: Mirza Riyasat Ali 2022 年 11 月 12 日
Hi,
I want to compare two matrices for equal values, and I want to know if there is a build-in function to do this. Ihaven't been able to find it in the MATLAB help.
example: A=[1 2 3; 4 5 6; 7 8 9] B=[9 8 7; 6 5 4; 3 2 1] this should return something like result=[0 0 0;0 1 0;0 0 0] so I can see there is an equal number on the same position in both matrices and the position that it is in.
Thanks!
Ellen
  2 件のコメント
João Peixoto
João Peixoto 2015 年 10 月 13 日
have you tried? result = A==B;
SALAR SHAIKHAH
SALAR SHAIKHAH 2016 年 11 月 25 日
You can do as: C=A==B, The matrix C will contain the result of comparison... For more comparison, you can see following link: https://www.mathworks.com/help/matlab/matlab_prog/array-comparison-with-relational-operators.html

サインインしてコメントする。

採用された回答

Sean de Wolski
Sean de Wolski 2011 年 5 月 23 日
result = A==B;
  3 件のコメント
Sincloe Brans
Sincloe Brans 2014 年 8 月 12 日
This doesn't work for two matrix with different dimensions, any way to compare two matrix with different rows and same number of column (eg A=50*16 vs B=100*16)?
Sean de Wolski
Sean de Wolski 2014 年 8 月 12 日
isequal
Sincloe, please ask this as a new question next time!

サインインしてコメントする。

その他の回答 (4 件)

Shubham Patel
Shubham Patel 2019 年 3 月 6 日
Use this
isequal(A,B)
  1 件のコメント
AMAN GAUTAM
AMAN GAUTAM 2019 年 8 月 16 日
Sir,Why its result is "Non orthogonal".While all element of inverse matrix R1 and R_UTOF is same, Please tell mistakes-
angle=input('Enter euler angle in order');
alpha=(pi/180).*angle(1,1);
beta=(pi/180).*angle(1,1);
gama=(pi/180).*angle(1,1);
R_z_alpha=[cos(alpha) -sin(alpha) 0;sin(alpha) cos(alpha) 0;0 0 1];
R_y_beta=[cos(beta) 0 -sin(beta);0 1 0;sin(beta) 0 cos(beta)];
R_x_gama=[1 0 0;0 cos(gama) -sin(gama);0 sin(gama) cos(gama)];
disp('Rotation matrix is ');
R_UTOF=R_z_alpha*R_y_beta*R_x_gama; % rotation converson matrix from Universal to final frame
disp(R_UTOF);
disp('Transpose of rotation matrix is');
disp(R_UTOF');
disp('Inverse of rotation matrix is');
R1=inv(R_UTOF);
disp(R1);
if isequal(R1,R_UTOF')
disp("Rotation matrix is Orthogonal");
else
disp("Rotation matrix is non Orthogonal");
end

サインインしてコメントする。


Kiarash Ahi
Kiarash Ahi 2014 年 7 月 21 日
編集済み: Kiarash Ahi 2014 年 7 月 21 日
How if I want two compare the two matrices and get only one digit; I mean 1 if both were the same and 0 if at least two element of the matrices differ?
  3 件のコメント
Niko
Niko 2014 年 8 月 12 日
Salah Alhaithemy
Salah Alhaithemy 2016 年 3 月 10 日
isempty(find(A==B))

サインインしてコメントする。


kevin harianto
kevin harianto 2022 年 4 月 4 日
Is there documentation to check whether a matric is greater than in terms of size for each of the dimensions?

Mirza Riyasat Ali
Mirza Riyasat Ali 2022 年 11 月 12 日

カテゴリ

Help Center および File ExchangeResizing and Reshaping Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by