0

配列の比較に関する質問を投稿しました。私はそれで助けを得ました、そしてそれはこのようになります:

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未満であるためです。

4

2 に答える 2

4

本当にやりたいですa/bか?これが、劣決定方程式系に対する最小二乗法での解a*X = bです。詳細については、 mrdividemldivideを参照してください。

どちらがとmax(a./b)の対応する要素の比率を計算し、その最大値を取りますか。(エラーチェックでも同じ)ab

error_countところで、最初のループの最初にリセットしたため、エラーチェックは実行されません。そのループから移動すると、それも修正されます。

于 2012-12-13T19:50:36.153 に答える
1

Let's focus on these few lines:

a = max(person(z,:),person1);
b = min(person(z,:),person1);
percent_error = b/a;
if percent_error >= 0.85

a is going to return the higher of the two values, in the form of an array. b will do the same thing, but the lower. Thus, you have something like this:

a=[98 208 35 114]; b=[93 206 34 107];

The next step you do is a division. However, this is actually a matrix division. In this case, percent_error=0.97408 But I'm not sure why you want to do a least squared sense division, as Guther pointed out. It seems more likely that you want to do something like mean(a./b), to average out the values.\

A few other things that I see:

  • height_check=b/a; Seems like it should be related to bh./ah
  • I'm really unsure about your methods of comparison as a whole. It seems like you would do better to compare each value vs the range of possible values, instead of the division operation you have.

I'm not sure exactly what you are trying to do, but I think you want to do something more like this, with some work on your assumptions required as well:

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 = mean(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=bh./ah;
           if height_check >= 0.98
               disp(['Match, its ', allNames{z} ,'!'])
               break
           end
       end
    elseif percent_error < 0.85
        disp('Person is unknown!')
    end
end
于 2012-12-13T19:52:05.010 に答える