how to define Sorenson distance as a function?
4 次查看(过去 30 天)
显示 更早的评论
I wrote this function for computing Sorenson distance (the formula of Sorenson is attached
), Is this code right?
![sorenson.jpg](https://www.mathworks.com/matlabcentral/answers/uploaded_files/251761/sorenson.jpeg)
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 个评论
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Dynamic System Models 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!