How to change negative values in anonymous function to zero and call it to next function?

1 回表示 (過去 30 日間)
Hello , I have a similar kind of problem like y = [1 2 1 1 1] and z = [1 2 -3 4 -5] and v(z) = z^3 now i have to calculate h(z) = v(z).*y but the condition is when i calculate h only negative values in the anonymous fn of v(z) must become zero. can someone tell me how?
z = [1 2 -3 4 -5];
y = [1 2 1 1 1];
v =@ (z) z.^3;
h = v(z).*y
I am getting h = [1 16 -27 64 -125] but i need h = [1 16 0 64 0]

採用された回答

Matt J
Matt J 2020 年 10 月 9 日
v =@ (z) z.^3 .*(z>=0);

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2020 年 10 月 9 日
v = @(z) max(0,v).^3;

カテゴリ

Help Center および File ExchangeFunction Creation についてさらに検索

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by