L1 and l2 norm
180 次查看(过去 30 天)
显示 更早的评论
i'm trying to find the code not the function to implement L1 and L2 norm.
I'm trying to compute the L1 and L2 norm of pixels in a image to see the difference between them.
0 个评论
回答(2 个)
Johnathan Schaff
2018-3-15
编辑:Johnathan Schaff
2018-3-15
%Matrix Norm for Matrix A
%L1 Norm
l1 = max(sum(abs(A)));
matL1 = norm(A,1);
%L2 Norm
l2 = max(svd(A));
matL2 = norm(A,2);
%Comparison
fprintf('L1 Norm | %g\nMATLAB L1 Norm | %g\n',l1,matL1);
fprintf('L2 Norm | %g\nMATLAB L2 Norm | %g\n',l2,matL2);
%Vector Norm for Vector B
%L1 Norm
l1 = (sum(abs(B)));
matL1 = norm(B,1);
%L2 Norm
l2 = sqrt(sum(abs(B).^2));
matL2 = norm(B,2);
%Comparison
fprintf('\nL1 Norm | %g\nMATLAB L1 Norm | %g\n',l1,matL1);
fprintf('L2 Norm | %g\nMATLAB L2 Norm | %g\n',l2,matL2);
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!