Function, How to write this formula in Matlab

I have been trying to write this formula in matlab, but I have not had many results. The formula is as follows:
in addition, the Ln must have a conditional, where, if Pi is negative or equal to 0, the result of the ln of that Pi is 0.
If someone can help me, it would be very helpful
Thanks

回答(1 个)

W = log(p);
W(p <= 0) = 0;
N = exp(-sum( p .* W));

2 个评论

Hi Walter, thank you for your answer.
But I made some mistakes when i tried to explain my question
Ln = log(p);
Ln(p <= 0) = 0;
N = exp(-sum( p .* Ln));

请先登录,再进行评论。

类别

帮助中心File Exchange 中查找有关 Get Started with MATLAB 的更多信息

产品

版本

R2021b

标签

Community Treasure Hunt

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

Start Hunting!

Translated by