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.
a = max(person(z,:),person1);you wrote that you want to "...find out which array is bigger than the other, then I divide the smaller by the larger." If you would clarify in what sense you want to find the larger of these two vectors, then you'll find your answers more informative.( e.g. Do you want to compare the sum of the vectors? Do you want to know which vector contains the largest element?)a = max(person(z,:),person1);is an element-wise comparison. That means it compares person(z,ii) to person1(ii) and puts the bigger of the two into a(ii), for all ii.ratio<1so that's easier to compare. There are other ways for doing this, but I don't see any major flaws doing it this way..