-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjpa_getInitialienOfSting.m
More file actions
75 lines (72 loc) · 2.25 KB
/
jpa_getInitialienOfSting.m
File metadata and controls
75 lines (72 loc) · 2.25 KB
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
function initials = jpa_getInitialienOfSting(str)
% Function returnes the first 3 Characters of each Cell-String in one
% concatenated string alphabetically ordered for each Column!
% The first letter of each Cell String will be capital
% the rest will be lowercase.
%
% Syntax:
% initials = jpa_getInitialienOfSting(str)
%
% Inputs:
% str - Cell which contains a various number of letters
%
% Outputs:
% init - String which only contains the first 3 letters of every string
% in str concatenated to a large String
%
% Example:
% initials = jpa_depthSearch({'String1', 'eXAm2' , 'test3'})
% -> Output: {StrExaTes}
%
% Other m-files required: none
% Subfunctions: none
% MAT-files required: none
%
% See also:
% Author: Jan Albrecht
% Work address:
% email: jan-philipp.albrecht@charite.de, j.p.albrecht@fu-berlin.de
% Website:
% Sep 2015; Last revision: 14-Sep-2015
%------------- BEGIN CODE --------------
[a, b] = size(str);
% Initialisation
initField = repmat({''},a,b);
initials = repmat({''},1,b);
% Loops through rows and cols
for j=1:1:b
for i=1:1:a
% check whether Char or not
if ischar(str{i,j})
% check for empty strings
if ~strcmp(str{i,j} , '')
% check for length
if length(str{i,j}) > 3
% Upper first letter, lower rest letters, save in init
initField{i,j} = strcat(upper(str{i,j}(1)), lower(str{i,j}(2:3)) );
else
if length(str{i,j}) > 1
% Upper first letter, lower rest letters, save in init
initField{i,j} = strcat(upper(str{i,j}(1)), lower(str{i,j}(2:length(str{i,j}))) );
else
% Upper first letter, save in init
initField{i,j} = upper(str{i,j}(1));
end
end
end
else % case: not a char
error('Input contains non-Char Elements!')
end
end
end
% order them and write them in one String for each Col!
for i=1:1:b
initField(:,i) = sort(initField(:,i));
end
for j=1:1:a
for i=1:1:b
initials{i} = strcat(initials{i},initField{j,i});
end
end
end
%------------- END CODE --------------