Effacer les filtres
Effacer les filtres

Unable to compare equality of two matrices

1 vue (au cours des 30 derniers jours)
N/A
N/A le 27 Déc 2021
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

Réponses (1)

Walter Roberson
Walter Roberson le 27 Déc 2021
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?

Catégories

En savoir plus sur Multidimensional Arrays 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!

Translated by