How to code below mathematical formula?
2 次查看(过去 30 天)
显示 更早的评论
I want to implement a below mathematical function in MATLAB, can anyone help me out?
![myop.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/227265/myop.png)
0 个评论
采纳的回答
更多回答(1 个)
KALYAN ACHARJYA
2019-7-3
编辑:KALYAN ACHARJYA
2019-7-3
x= %define x value range
n= %define n
threshold= %define threshold value
fx=x;
idx1=find(fx>=threshold);
fx(idx)=1;
idx1=find(fx<threshold);
fx(idx)=0;
MYOP=(sum(fx(1:n)))/n;
2 个评论
Stephen23
2019-7-3
编辑:Stephen23
2019-7-3
Note that this answer does not implement the formula given in the question.
In particular it does not include f(x) in any way within the sum, as the question indicates. It also does not vectorize the generation of fx (or use a loop), so it is unlikely to be a useful approach anyway.
The code throws an error when run because xi is not defined:
Undefined function 'xi' for input arguments of type 'double'.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!