フィルターのクリア

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 Center および File ExchangeMultidimensional Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by