-
Notifications
You must be signed in to change notification settings - Fork 5
/
read_persistence_interval_distribution.m
51 lines (43 loc) · 1.52 KB
/
read_persistence_interval_distribution.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
function [ distribution, infinite_intervals ] = ...
read_persistence_interval_distribution(fileName, numFiltrations)
% ----------------------------------------------------------------
% READ PERSISTENCE INTERVAL DISTRIBUTION
% written by Chad Giusti, 6/2014
%
% Read the distribution of persistence interval lengths for a
% particular homological dimension from Perseus output files.
%
% INPUT:
% fileName: Name of the file to read, with complete path if not
% the working directory
%
% OUTPUT:
% distribution: An array containing a the distribution of interval
% lengths. The final element is for "infinite" intervals with
% no endpoint.
% ----------------------------------------------------------------
distribution = zeros(1, numFiltrations);
infinite_intervals = 0;
% ----------------------------------------------------------------
% Open the file and read the outputs into the array
% ----------------------------------------------------------------
if exist(fileName, 'file')
try
fid = fopen(fileName, 'r');
tline = fgets(fid);
while ischar(tline)
interval = str2num(tline);
if (interval(end) == -1)
infinite_intervals = infinite_intervals + 1;
else
len = interval(end) - interval(1);
distribution(len) = distribution(len)+1;
end
tline = fgets(fid);
end
fclose(fid);
catch exception
disp(exception.message);
rethrow(exception);
end
end