我发布了一个关于比较数组的问题。我得到了帮助,它是这样的:
allNames = {'Cameron'; 'David'; 'Mike'; 'Bill'; 'Joe'};
%Here is how you then would get hold of them in a loop:
person = [98 206 35 114;
60 206 28 52;
100 210 31 116;
69 217 26 35;
88 213 42 100];
person1 = [93 208 34 107];
allNames = {'Cameron'; 'David'; 'Mike'; 'Bill'; 'Joe'};
for z = 1:5
a = max(person(z,:),person1);
b = min(person(z,:),person1);
percent_error = b/a;
if percent_error >= 0.85
%title(['Match, its ', allNames{z} ,'!'],...
% 'Position',[50,20,9],'FontSize',12);
disp(['Match, its ', allNames{z} ,'!'])
end
end
运行代码会显示:
Match, its Cameron!
Match, its David!
Match, its Mike!
Match, its Joe!
现在我想做一个错误检查,因此如果将打印多个名称,则第二列将亲自打印,而person1将通过将它们彼此相除来进行比较。如果商至少为 0.98,则打印该名称且仅打印该名称。这是我尝试过的,错误检查未被识别。
person1(count,:)=[pace height build stride]
allNames = {'Kassie'; 'Keyton'; 'Cameron'; 'Joseph'; 'Josh'};
for z = 1:5
a = max(person(z,:),person1);
b = min(person(z,:),person1);
percent_error = b/a;
error_count = 0;
if percent_error >= 0.85
%title(['Match, its ', allNames{z} ,'!'],...
% 'Position',[50,20,9],'FontSize',12);
disp(['Match, its ', allNames{z} ,'!'])
error_count = error_count+1;
if error_count >= 2
ah=max(person(:,2),person1(1,2));
bh=min(person(:,2),person1(1,2));
height_check=b/a;
if height_check >= 0.98
disp(['Match, its ', allNames{z} ,'!'])
break
end
end
elseif percent_error < 0.85
disp('Person is unknown!')
end
end
结果如下:
person1 =
75 168 6 69
Person is unknown!
Match, its Keyton!
Person is unknown!
Match, its Joseph!
Person is unknown!
>> person
person =
38 163 36 38
70 162 35 73
47 166 39 28
70 163 39 62
27 176 32 27
所有person1都应该是“人员未知!” 因为 Keyton 和 Joesph 在第二列中的值都小于 0.98。