MATLAB code that can replace the inbuilt function 'norm'

Hello, I need to substitute the inbuilt function 'norm' with other matlab code that execute the same function. This is because the function 'norm' is not permitted to be translated using the MATLAB HDL Coder function.
Thank you in advance for the help!

5 件のコメント

amin ya
amin ya 2019 年 3 月 15 日
There are many norm functions in MATLAB, which one do you mean?
Have you looked here:
Yue Han Seow
Yue Han Seow 2019 年 3 月 15 日
I'm not really sure which type of norm it is,
w1 = norm(win,1)
this is the equation that uses the norm function
John D'Errico
John D'Errico 2019 年 3 月 15 日
As importantly, what is win? Is win a vector? Is win a matrix?
Yue Han Seow
Yue Han Seow 2019 年 3 月 15 日
win is a window

サインインしてコメントする。

 採用された回答

John D'Errico
John D'Errico 2019 年 3 月 15 日
編集済み: John D'Errico 2019 年 3 月 15 日

0 投票

I suppose I can write a simple 1-norm code, that will work for a vector OR matrix.
Thus, the 1-norm of a vector is the sum of absolute values of the vector. So, if X is a vector, then norm(X,1) == sum(abs(X)).
If X is a matrix? Then the 1-norm is the maximum sum of all columns of the matrix. We can see how this works:
X = rand(3,3)
X =
0.72105 0.21868 0.063591
0.5225 0.1058 0.40458
0.9937 0.1097 0.44837
>> norm(X)
ans =
1.4581
>> max(sum(abs(X),1))
ans =
2.2372
>> norm(X,1)
ans =
2.2372
So now we can write a code that will work for any vector or matrix, computing the 1-norm.
function res = norm1(X)
if isvector(X)
res = sum(abs(X));
else
res = max(sum(abs(X),1));
end
This code does not replace norm, in the sense that it is far simpler. It does not compute a 2-norm, or any other norm. It does not work for 3-d matrices, but then, neither does norm work there.

1 件のコメント

Yue Han Seow
Yue Han Seow 2019 年 3 月 15 日
Thank you so much for your explanation and example! It helps me to understand it better!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by