-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFridericiaAPDCorrect.m
148 lines (127 loc) · 4.37 KB
/
FridericiaAPDCorrect.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
function [] = FridericiaAPDCorrect()
%Write script to plot APD and find cycle length (CL, 1/BPM). Finds a linear
%best fit to then correct APDs to find APDc values.
%Define variables
allAvg_apd50 = zeros(1);
allAvg_apd90 = zeros(1);
allAvg_apd30 = zeros(1);
allCL = zeros(1);
allstd_apd50 = zeros(1);
allstd_apd90 = zeros(1);
allstd_apd30 = zeros(1);
%Load APD and BPM from traces
%%select .mat files generated from apdCalc analyze
[Filelist,Pathname] = uigetfile('C:\Users\Steven Boggess\Documents\Miller Lab\Data\*.mat','File Selector','MultiSelect','on');
allData = struct();
numFiles = numel(Filelist);
for iFile = 1:numFiles % Loop over found files
Data = load(fullfile(Pathname, Filelist{1,iFile}));
Data = rmfield(Data , 'cAP_Data') ; %remove the table from files, avoid error
Fields = fieldnames(Data);
for iField = 1:numel(Fields) % Loop over fields of current file
aField = Fields{iField};
switch (aField)
case 'apd30'
apd30 = Data.(aField);
case 'apd50'
apd50 = Data.(aField);
case 'apd90'
apd90 = Data.(aField);
case 'BPM'
BPM = Data.(aField);
end
end
%Taking values from file in current loop, calculate CL and APD values.
%plot these values
%Calculate mean APD
avg_apd30 = mean(apd30);
avg_apd50 = mean(apd50);
avg_apd90 = mean(apd90);
%Calculate standard deviations
std_apd30 = std(apd30);
std_apd50 = std(apd50);
std_apd90 = std(apd90);
%Calculate Cycle Length (CL)
CL = 60/(BPM);
%Insert and combine values
if (allAvg_apd50(1,1) == 0)
allAvg_apd50 = avg_apd50;
allAvg_apd90 = avg_apd90;
allAvg_apd30 = avg_apd30;
allCL = CL;
allstd_apd50 = std_apd50;
allstd_apd90 = std_apd90;
allstd_apd30 = std_apd30;
else
allAvg_apd50(end+1) = avg_apd50;
allAvg_apd90(end+1) = avg_apd90;
allAvg_apd30(end+1) = avg_apd30;
allCL(end+1) = CL;
allstd_apd50(end+1) = std_apd50;
allstd_apd90(end+1) = std_apd90;
allstd_apd30(end+1) = std_apd30;
end
end
%Now find FcAPD50 values
F_APD50c = zeros(length(allAvg_apd50),1);
for j = 1:length(allAvg_apd50)
F_APD50c(j) = (allAvg_apd50(j)/((allCL(j))^(1/3))) ;
end
%Now find FcAPD90 values
F_APD90c = zeros(length(allAvg_apd90),1);
for k = 1:length(allAvg_apd90)
F_APD90c(k) = (allAvg_apd90(k)/((allCL(k))^(1/3))) ;
end
%Now find FcAPD30 values
F_APD30c = zeros(length(allAvg_apd30),1);
for k = 1:length(allAvg_apd30)
F_APD30c(k) = (allAvg_apd30(k)/((allCL(k))^(1/3)));
end
%transpose
allAvg_apd90 = allAvg_apd90.';
allAvg_apd50 = allAvg_apd50.';
allAvg_apd30 = allAvg_apd30.';
allCL = allCL.';
%Save the current data set
correctionFilename = input ('Please provide filename ');
if isempty(correctionFilename) == 1;
disp ('Please provide a string');
filename = input('Please provide filename ');
else
end
if ischar(correctionFilename) == 0;
disp ('Please provide a character in single quotations');
correctionFilename = input('Please provide filename ');
else
end
ThefullOutputName = [Pathname correctionFilename];
save(ThefullOutputName,'allCL');
save(ThefullOutputName,'F_APD30c','-append');
save(ThefullOutputName,'F_APD50c','-append');
save(ThefullOutputName,'F_APD90c','-append');
%Plot and save figures
figure('name','APD50 correction','numbertitle','off');
hold on;
title('APD50');
xlabel('Cycle Length');
ylabel('APD50(ms)');
scatter(allCL , allAvg_apd50 , 'r' , 's' , 'filled');
scatter(allCL , F_APD50c,'o','o','filled'); %plot corrected values
legend('Data' , 'Corrected Data' ,'Location' , 'best');
figure('name','APD90 correction','numbertitle','off');
hold on;
title('APD90');
xlabel('Cycle Length');
ylabel('APD90(ms)');
scatter(allCL , allAvg_apd90 , 'b' , 's' , 'filled');
scatter(allCL , F_APD90c,'m','o','filled');
legend('Data' , 'Corrected Data','Location','best');
figure('name','APD30 correction','numbertitle','off');
hold on;
title('APD30');
xlabel('Cycle Length');
ylabel('APD30(ms)');
scatter(allCL , allAvg_apd30 , 'b' , 's' , 'filled');
scatter(allCL , F_APD30c,'m','o','filled');
legend('Data', 'Corrected Data','Location','best');
end