How to code below mathematical formula?

조회 수: 1 (최근 30일)
Hassan Ashraf
Hassan Ashraf 2019년 7월 3일
편집: KALYAN ACHARJYA 2019년 7월 3일
I want to implement a below mathematical function in MATLAB, can anyone help me out?
myop.png

채택된 답변

Stephen23
Stephen23 2019년 7월 3일
편집: Stephen23 2019년 7월 3일
The simple MATLAB solution:
>> x = 1:30;
>> t = 23; % threshold
>> MYOP = sum(x>=t)/numel(x)
MYOP =
0.26667

추가 답변 (1개)

KALYAN ACHARJYA
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
Hassan Ashraf
Hassan Ashraf 2019년 7월 3일
Thank you :)
Stephen23
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'.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Simulink에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by