annotate evaluationtools/compareorderedsets.m @ 1:8973548174c1 tip

adding tools to repo
author christopherh
date Mon, 06 May 2013 14:43:47 +0100
parents
children
rev   line source
christopherh@1 1
christopherh@1 2
christopherh@1 3 function [match,success,errormessage] = compareorderedsets(set1,set2,cardinality)
christopherh@1 4
christopherh@1 5 errormessage = '';
christopherh@1 6 success = 1;
christopherh@1 7 match = 0;
christopherh@1 8
christopherh@1 9 if nargin<3
christopherh@1 10 cardinality = 6;
christopherh@1 11 end
christopherh@1 12
christopherh@1 13
christopherh@1 14
christopherh@1 15
christopherh@1 16 % check to see if sets are same type
christopherh@1 17 if strcmp(class(set1),class(set2))
christopherh@1 18 % check whether dealing with strings, cell arrays of chars or arrays of ints
christopherh@1 19 if ischar(set1)
christopherh@1 20
christopherh@1 21 % compare strings
christopherh@1 22 if strcmp(set1,set2)
christopherh@1 23 match = 1;
christopherh@1 24 else
christopherh@1 25 match = 0;
christopherh@1 26 end
christopherh@1 27 end
christopherh@1 28
christopherh@1 29 if iscell(set1)
christopherh@1 30 % compare cell arrays of characters
christopherh@1 31
christopherh@1 32 % fill blank spaces so that cardinalities match
christopherh@1 33 while length(set1)<cardinality
christopherh@1 34 set1 = [set1, '-'];
christopherh@1 35 end
christopherh@1 36
christopherh@1 37 while length(set2)<cardinality
christopherh@1 38 set2 = [set2, '-'];
christopherh@1 39 end
christopherh@1 40
christopherh@1 41 for i = 1:cardinality
christopherh@1 42
christopherh@1 43 if strcmp(set1{i},set2{i})
christopherh@1 44 match = 1;
christopherh@1 45 else
christopherh@1 46 match = 0;
christopherh@1 47 break;
christopherh@1 48 end
christopherh@1 49 end
christopherh@1 50 end
christopherh@1 51
christopherh@1 52 if isnumeric(set1) && isnumeric(set2)
christopherh@1 53 % compare integers
christopherh@1 54
christopherh@1 55 % fill blank spaces so that cardinalities match
christopherh@1 56 while length(set1)<cardinality
christopherh@1 57 set1 = [set1,-1];
christopherh@1 58 end
christopherh@1 59
christopherh@1 60 while length(set2)<cardinality
christopherh@1 61 set2 = [set2,-1];
christopherh@1 62 end
christopherh@1 63
christopherh@1 64 for i = 1:cardinality
christopherh@1 65
christopherh@1 66 if set1(i)==set2(i)
christopherh@1 67 match = 1;
christopherh@1 68 else
christopherh@1 69 match = 0;
christopherh@1 70 break;
christopherh@1 71 end
christopherh@1 72 end
christopherh@1 73 end
christopherh@1 74 else
christopherh@1 75 % trying to compare mixed data types
christopherh@1 76 errormessage = 'Error in compareorderedsets: trying to compare mixed data types';
christopherh@1 77 success= 0;
christopherh@1 78 end