how to define Sorenson distance as a function?

1 次查看(过去 30 天)
I wrote this function for computing Sorenson distance (the formula of Sorenson is attachedsorenson.jpg), Is this code right?
the colon is 62*2001 dataset(attached), when I use this function in my program instead of 62 instances I found 2 instances(rows) in the output.
load colon.mat
data=colon;
[n,m]=size(data);
l=1;
t=1;
data1=[];
data2=[];
for i=1:n
if data(i,m)==1
data1(l,:)=data(i,:);
l=l+1;
else
data2(t,:)=data(i,:);
t=t+1;
end
end
if t>l
data1(l:t-1,:)=0;
else
data2(t:l-1,:)=0;
end
%computing Distance measures
for i=1: m
thisCol1=data1(:,i);
thisCol2=data2(:,i);
a(i)=fSorensonDist(thisCol1,thisCol2);
end
[A,indA]=sort(a,'descend');
datas17=data(:,indA(1,10));
datas17=[datas17,data(:,m)];
save('datas17.mat');
I defined the sorenson function for computing distance:
function [ fsnd ] = fSorensonDist( p,q )
fsnd=sum(abs(p-q))/sum(p+q);
end
I'll be very grateful to have your opinions. Thanks

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Dynamic System Models 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by