Matlab: compare tables & hellip; after

I posted a question concerning comparing arrays. I got help with that and it goes something like this:

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

Running the code it will display:

Match, its Cameron!
Match, its David!
Match, its Mike!
Match, its Joe!

Now I want to do an error check so if more than one name will be printed the second column in person and person1 will be compared by dividing them by each other. And if the quotient comes out to be at least 0.98, then that name gets printed and only that name. This is what I tried and the error check is not being recognized.

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

Here are the results:

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

all of person1 should be "Person is unknown!" because the values in the 2nd column for Keyton and Joesph are both less than 0.98.

Do you really want to do a/b ? That's the solution in the least squares sense to the underdetermined system of equations a*X = b . See mrdivide and mldivide for more details on this.

Don't you rather want max(a./b) which calculates the ratio of the corresponding elements in a and b and takes the maximum of that. (same thing in the error check)

Btw, your error check isn't run, because you reset error_count in the beginning of the first loop. Move it out of that loop and that's also fixed.

我来评几句
登录后评论

已发表评论数()

相关站点

+订阅
热门文章