%Dolev算法
clear all;
clc;
S1 = [4.7 1.6 3.0 1.8 3.0];
S2 = [4.7 1.6 3.0 1.8 1.0];
S3 = [4.7 1.6 3.0 1.8 2.5];
S4 = [4.7 1.6 3.0 1.8 0.9];
V = zeros(1,4);% New values of PEs,存的是每一轮计算之后的S结果
P = zeros(1,6);% Precisions,最大最小之间的插值
S = [S1;S2;S3;S4];%直接把像上面的整体矩阵排成大的矩阵
R = 0.01;
k = 1;
a = 5;
d = 10;%迭代次数
while a > 0.0001 ,
%for e = 1:d
for i = 1:4 %分别对每一行进行处理
temp = sort(S(i,:)); % sort the values in the set
V(i) = mean(temp(2:4));% Calculate the average of the set without the lowest value and the highest value
end %每一行排完以后都给V
a = Var(V); % Calculate the Precision,记差值
P(k) = a;
SRecord(k,:) = V;
fprintf('迭代次数:%.0f\t\n', k);
fprintf('S1,S2,S3,S4:%.2f\t%.2f\t%.2f\t%.2f\n',V(1),V(2),V(3),V(4));
fprintf('Precision:%f\n\n',P(k));
k = k+1;
for i = 1:4
for j= 1:4
S(i,j) = V(j);
end
end
end
[m1,n1] = size(SRecord);
S11(1,2:m1+1) = SRecord(:,1);
S22(1,2:m1+1) = SRecord(:,2);
S33(1,2:m1+1) = SRecord(:,3);
S44(1,2:m1+1) = SRecord(:,4);
S11(1,1) = 4.7;
S22(1,1) = 1.6;
S33(1,1) = 3;
S44(1,1) = 1.8;
i = 1:m1;
plot(i,S11(1,i),'-r*');
hold on;
i = 1:m1;
plot(i,S22(1,i),'-b*');
hold on;
plot(i,S33(1,i),'-g*');
hold on;
plot(i,S44(1,i),'-k*');
hold on;
title('Dolev算法的准确度');
xlabel('迭代次数');
ylabel('S1-S4融合结果');
legend('S1','S2','S3','S4');
figure;
[m,n] = size(P);
m2 = 1:n;
plot(m2,P(m2),'-*r');
title('Dolev算法的精度');
xlabel('迭代次数');
ylabel('S1-S4方差');