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

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