-
Notifications
You must be signed in to change notification settings - Fork 1
/
i4col_compare.m
95 lines (82 loc) · 1.87 KB
/
i4col_compare.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
function isgn = i4col_compare ( m, n, a, i, j )
%*****************************************************************************80
%
%% I4COL_COMPARE compares columns I and J of a integer array.
%
% Example:
%
% Input:
%
% M = 3, N = 4, I = 2, J = 4
%
% A = (
% 1 2 3 4
% 5 6 7 8
% 9 10 11 12 )
%
% Output:
%
% ISGN = -1
%
% Licensing:
%
% This code is distributed under the GNU LGPL license.
%
% Parameters:
%
% Input, integer M, N, the number of rows and columns.
%
% Input, integer A(M,N), an array of N columns of vectors of length M.
%
% Input, integer I, J, the columns to be compared.
% I and J must be between 1 and N.
%
% Output, integer ISGN, the results of the comparison:
% -1, column I < column J,
% 0, column I = column J,
% +1, column J < column I.
%
%
% Check.
%
if ( i < 1)
fprintf ( 1, '\n' );
fprintf ( 1, 'I4COL_COMPARE - Fatal error!\n' );
fprintf ( 1, ' Column index I = %d < 1.\n', i );
error ( 'I4COL_COMPARE - Fatal error!' );
end
if ( n < i )
fprintf ( 1, '\n' );
fprintf ( 1, 'I4COL_COMPARE - Fatal error!\n' );
fprintf ( 1, ' N = %d < column index I = %d.\n', n, i );
error ( 'I4COL_COMPARE - Fatal error!' );
end
if ( j < 1 )
fprintf ( 1, '\n' );
fprintf ( 1, 'I4COL_COMPARE - Fatal error!\n' );
fprintf ( 1, ' Column index J = %d < 1.\n', j );
error ( 'I4COL_COMPARE - Fatal error!' );
end
if ( n < j )
fprintf ( 1, '\n' );
fprintf ( 1, 'I4COL_COMPARE - Fatal error!\n' );
fprintf ( 1, ' N = %d < column index J = %d.\n', n, j );
error ( 'I4COL_COMPARE - Fatal error!' );
end
isgn = 0;
if ( i == j )
return
end
k = 1;
while ( k <= m )
if ( a(k,i) < a(k,j) )
isgn = -1;
return
elseif ( a(k,j) < a(k,i) )
isgn = +1;
return
end
k = k + 1;
end
return
end