配列の比較に関する質問を投稿しました。私はそれで助けを得ました、そしてそれはこのようになります:
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の2列目の値はどちらも0.98未満であるためです。