I wrote a function for a math formula, may I ask you please check my code?

조회 수: 2 (최근 30일)
Hey all,
For my research, I needed to calculate some formula, So I searched everywhere, including Matlab file exchange and find nothing about the formula that I needed. Hence I decided to write a function for them and use them in my code. This is the very first time for me to write a function and also the first time to write a math formula. May I please ask you to check if where I do wrong?
Here is the formula:
And here is the function I wrote (I considered O as x and M as y):
function index_agreement = indexagreement(x,y)
%In the name of God - This function calculate
% Detailed explanation goes here
A = sum((y-x).^2);
B = abs(y - (mean(x)));
C = x - abs((mean(x)));
D = sum((B+C).^2);
index_agreement = 1 - (D);
end
Description: I run this function successfully, but I'm not sure about results because I believe they are not reasonable.
I want to thank you all.
Best Regards

채택된 답변

Image Analyst
Image Analyst 2020년 2월 15일
Assuming vertical bars mean absolute value and not modulus...
You got C wrong. Try
C = abs(x - abs((mean(x)));
then you need
index_agreement = 1 - abs(A / D);
There may be more errors, but I stopped looking once I found those errors.
  댓글 수: 5
BN
BN 2020년 2월 15일
I'm sorry it's my bad, jsut one thing in this line:
index_agreement = 1 - abs(A / D);
why we should add an abs?
the formula is 1-(fraction) not 1-|fraction|. in fact, in the image, they used [] as a parenthesis.
is still should be :
index_agreement = 1 - abs(A / D);
%or now I should use:
index_agreement = 1 - (A / D);
?
Thank you
Image Analyst
Image Analyst 2020년 2월 16일
I thought it was weird because it should be positive already, but I just saw the vertical lines on either side of the fraction so I just said to do abs. If they are brackets, then I didn't notice the little "feet" on the bottom of the brackets, and the top ones are missing because your image clipped them off. But, no, you do not need the abs().

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Graphics Object Programming에 대해 자세히 알아보기

태그

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by