sephaCe is an open source project powered by Assembla

Assembla offers free public and private SVN/Git repositories and project hosting with bug/issue tracking and collaboration tools.

/
 
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
% =========================================================================
% analyseFileName.m
%   Rehan Ali, 4th Nov 2006
%   Strips out focal distance information from image filenames
%   e.g. HeLa1_1705_trans.ics.bmp  --> 1705 um
%
%   Inputs:     fileName        String filename
%               prefix          String char(s) preceding numbers of interest
%   Outputs:    n               Numeric value required
% =========================================================================

function [n] = analyseFileName(fileName,prefix)

    numregion = 0;
    count = 1;
    arrN = 0;
    n = 0;

    % find location of prefix in filename string
    if (regexp(fileName, prefix) > 0)
        pos = regexp(fileName, prefix) + length(prefix);
    end

    for i = pos : length(fileName)
        % check if current character is numeric
        if ~isempty(str2num(fileName(i)))
            % if current char
            if numregion == 0
                arrN(count) = str2num(fileName(i));
                numregion = 1;
                count = count + 1;
            elseif numregion == 1
                arrN(count) = str2num(fileName(i));
                count = count + 1;
            end
        else
            % if nonnumeric but we were previously in a numeric region,
            % then terminate code
            if numregion == 1
                break
            end
        end

    end

    arrN = fliplr(arrN);
    for i = 1 : length(arrN)
        n = n + arrN(i)*10^(i-1);
    end
Ajax-loader Loading, please wait...