필터 지우기
필터 지우기

Unable to compare equality of two matrices

조회 수: 1 (최근 30일)
N/A
N/A 2021년 12월 27일
답변: Walter Roberson 2021년 12월 27일
I am trying to compare the two 4x4 matrices below and generate a success message, but I see that the code is able to display a success message only for the first element of each row. Can anyone spot where I made the mistake please?
Rotation_matrix = rotm2tform([0.9254 0.0180 0.3785; 0.1632 0.8826 -0.4410; -0.3420 0.4698 0.8138])
res = rpy2tr(30*pi/180,20*pi/180,10*pi/180)
k=0
for i = 1:size(Rotation_matrix)
for j = 1:size(res)
if isequal(i,j)
continue
else
disp("Fail")
k=1;
end
end
end
if k==0
disp("Verification success")
end
Thank you

답변 (1개)

Walter Roberson
Walter Roberson 2021년 12월 27일
size() of a variable, when no option is provided in the size() call, always returns a vector, even if the variable is a scalar. When you use 1:size() then you are using 1 colon a vector . MATLAB does define that: it takes the first element of the vector. So 1:size(Rotation_matrix) is going to be the same as 1:size(Rotation_matrix,1) which might not be what you want.
Question: why are you comparing the indices instead of comparing the matrix indexed at the indices?

카테고리

Help CenterFile Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by