Help with element manipulation of matrix
1 回表示 (過去 30 日間)
古いコメントを表示
Matthew Lozancich
2017 年 11 月 12 日
編集済み: Walter Roberson
2017 年 11 月 12 日
So the question I have been asked to do is:
Write a function called digit_compare.m which takes as input two 28 × 28 matrices, and returns the sum of the squares of the differences between the corresponding elements.
Here is what I have done so far. What did I do wrong?
function sum=digit_compare(X,Z)
X=zeros(28);
Z=zeros(28);
n=0;
sum=0;
for i=[1:28]
for j=[1:28]
n=((X(i,j))-(Z(i,j))).^2;
sum=sum+n;
end
end
end
0 件のコメント
採用された回答
Walter Roberson
2017 年 11 月 12 日
編集済み: Walter Roberson
2017 年 11 月 12 日
You did not take into account the possibility that the inputs might be unsigned integers. When you subtract a larger unsigned integer from a smaller unsigned integer, the result is 0 rather than a negative number.
Also, you overwrite all user-provided inputs with zeros.
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Matrix Indexing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!