Skip to content

Commit

Permalink
uploading matlab files
Browse files Browse the repository at this point in the history
  • Loading branch information
aflyax committed Nov 11, 2014
1 parent c7653d2 commit a54e469
Show file tree
Hide file tree
Showing 24 changed files with 850 additions and 42 deletions.
39 changes: 39 additions & 0 deletions AF_trapezoid_integration_v2.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
%initializing

d_area = 0;

% d = your data
% enter your values here:
d_start = 150;
d_end = 600;

%num_intervals = 50;

%interval = ceil( (d_end-d_start)/num_intervals );

interval = 1;

d_b = d - d(d_start); %subtracting baseline

x = (d_start : interval : d_end)';
y = d_b (x);

%plotting
figure; hold on
plot (d);

%AF trapezoid integration
for i = 1 : size(x)-1
d_area (i) = (x(i+1) - x(i)) * ((y(i) + y(i+1))/2);

%plotting trapezoid
t_x = [x(i), x(i), x(i+1), x(i+1)];
t_y = [0, y(i), y(i+1), 0];

fill (t_x, t_y, 'r');
end

AF_area = sum(d_area)

%trapz integration
trapz_area = trapz(x,y)
Binary file added EPSC non-silencing.fig
Binary file not shown.
12 changes: 12 additions & 0 deletions IclTrace.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
classdef IclTrace
%ICLTRACE Summary of this class goes here
% Detailed explanation goes here

properties
end

methods
end

end

62 changes: 20 additions & 42 deletions anal_events.m
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@


%% get the data, init constants

clear all;
Expand All @@ -22,6 +24,7 @@
% find peak at min (stimulus start : peak_end)

figure; hold on;
xlim([data_start, data_finish])
grey=[.8,.8,.8];

for i = 1 : size (fig_y)
Expand All @@ -33,77 +36,52 @@

% data_peaks_x(i) = find (data_sweeps{i} == data_peaks_y(i));
data_peaks_x(i) = data_peaks_x(i) + stim_start;

plot (data_sweeps{i}, 'Color', grey);
plot (data_peaks_x(i), data_peaks_y(i), 'ob');


%% finding the onset

data_pos = pos * data_sweeps{i};

d_smooth = smooth (data_pos, smooth_deg, 'loess');
diff_s = diff (d_smooth);

min_diff = std (diff_s(data_start:stim_start));


diff_pts = find (diff_s (stim_start:peak_end) > min_diff);

if diff_pts
event_onset_x (i) = diff_pts(1,1) + stim_start;
event_onset_y (i) = data_sweeps{i}(event_onset_x(i));

plot (event_onset_x (i), event_onset_y (i), 'ko');
else
event_onset_x (i) = nan;
event_onset_y (i) = nan;
end
[event_onset_x(i), event_onset_y(i)] = find_onset (data_sweeps{i}, pos);
plot (event_onset_x(i), event_onset_y(i), 'ob');
end

%% average and plot data

% figure(); hold on;

avg_peak_x = mean (data_peaks_x);
avg_peak_y = mean (data_peaks_y);

plot (avg_peak_x, avg_peak_y, 'bs');


avg_onset_x = nanmean (event_onset_x);
avg_onset_y = nanmean (event_onset_y);

plot (avg_onset_x, avg_onset_y, 'ks');


%% plotting the data and the average trace

dim = ndims(data_sweeps{2}); %# Get the number of dimensions for your arrays
M = cat(dim+1,data_sweeps{:}); %# Convert to a (dim+1)-dimensional matrix
y_mean = mean(M,dim+1); %# Get the mean across arrays

plot (y_mean, 'r');

[y_mean_peak_y y_mean_peak_x] = min (y_mean(stim_start:peak_end));
[y_mean_peak_y, y_mean_peak_x] = min (y_mean(stim_start:peak_end));
y_mean_peak_x = y_mean_peak_x + stim_start;

% y_mean_peak_x = find (y_mean==y_mean_peak_y);
plot (y_mean_peak_x, y_mean_peak_y, 'or');


[y_mean_onset_x y_mean_onset_y] = find_onset(y_mean, pos);
plot (y_mean_onset_x, y_mean_onset_y, 'or');

plot (y_mean_peak_x, y_mean_peak_y, 'or');

% data_pos = pos * y_mean(stim_start:data_finish);

data_pos = pos * y_mean();

d_smooth = smooth (data_pos, smooth_deg, 'loess');
diff_s = diff (d_smooth);

min_diff = std (diff_s(data_start:stim_start));

diff_pts = find (diff_s > min_diff);

event_onset_x = diff_pts(1,1) + stim_start;
event_onset_y = y_mean(event_onset_x);

plot (event_onset_x, event_onset_y, 'rs');

%% set axis limits
%% results

xlim([data_start, data_finish])
avg_onset_x
avg_onset_y
avg_peak_x
avg_peak_y
30 changes: 30 additions & 0 deletions avg_fig_traces.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
%% Averages traces on a selected figure

data_b = {};


h = findobj(gca,'Type','line');
fig_x=get(h,'Xdata');
fig_y=get(h,'Ydata');

data_start = 1900;
stim_start = 2000;
data_finish = 2600;


%subtract baseline
figure; hold on;
grey=[.8,.8,.8];

for i = 1 : size (fig_y)
base = mean (fig_y{i}(data_start:stim_start));
data_b{i} = fig_y{i} - base;

plot (data_b{i}(data_start:data_finish), 'Color', grey);
end

dim = ndims(data_b{2}); %# Get the number of dimensions for your arrays
M = cat(dim+1,data_b{:}); %# Convert to a (dim+1)-dimensional matrix
y_mean = mean(M,dim+1); %# Get the mean across arrays

plot (y_mean (data_start:data_finish), 'r');
133 changes: 133 additions & 0 deletions avgcurves.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
function avgCurve = avgcurves( inputX, inputY )
%avgcurves Takes (x,y) curve, averages y for any repeating
% x values.



%% sort inputX and inputY into a cell%
tempCell = sortvectors( inputX, inputY );

srtCurve.x = tempCell{1};
srtCurve.y = tempCell{2};


%% initializing newCurve and temp
% pre-allocating empty values for newCurve
newCurve.x = zeros(length(inputX),1);
newCurve.y = zeros(length(inputY),1);
newCurve.std = zeros(length(inputY),1);
newCurve.stdErr = zeros(length(inputY),1);

% initializing the first new X and Y
newCurve.x(1) = srtCurve.x(1);
newCurve.y(1) = srtCurve.y(1);

%temp is a buffer vector holding all y-val's that have the same x-val
temp = newCurve.y(1);

uniqI = 1; %the index of the current unique x,y

%% create averaged curve
for i = 2 : length( srtCurve.x ) %from the second value : last

if srtCurve.x(i) == srtCurve.x(i-1) %if two pts in a row are the same

% if temp ~= inf
temp = [temp; srtCurve.y(i)]; %add new point to temp
% else
% temp = srtCurve.y(i);
% end

%calculating y (avg), std and stdErr for the current x
newCurve.y(uniqI) = mean(temp(~isnan(temp))); %new y-value is mean(temp)
% newCurve.calcStd (uniqI, temp);

newCurve.std(uniqI) = std(temp(~isnan(temp)));
newCurve.stdErr(uniqI) = std(temp(~isnan(temp))) / sqrt( length(temp(~isnan(temp))) );

else
uniqI = uniqI + 1; %update uniqI

%update newCurve
newCurve.x(uniqI) = srtCurve.x(i);
newCurve.y(uniqI) = srtCurve.y(i);
% newCurve = newCurve.calcStd (uniqI, temp);

newCurve.std(uniqI) = std(temp(~isnan(temp)));
newCurve.stdErr(uniqI) = std(temp(~isnan(temp))) / sqrt( length(temp(~isnan(temp))) );

temp = newCurve.y(uniqI); %update temp to the next value

end %if

end %for

%delete zero values by making newCurve.x and .y go only until uniqI

% curve = {newCurve.x newCurve.y newCurve.std newCurve.stdErr};
%
% curve = curve(1:uniqI,1);
%
% [newCurve.x newCurve.y newCurve.std newCurve.stdErr] = curve{1,:};
%

% a little cell magic

% structure names
curveHeadings = {'x' 'y' 'std' 'stdErr'};

%conversting to a matrix
curve_mat = cell2mat( struct2cell(newCurve)' );

%assigining non-zero values to a cell
shortCurve_cell = num2cell( curve_mat(1:uniqI,:), 1)';

%converting back to a structure
newCurve = cell2struct (shortCurve_cell, curveHeadings, 1);





% newCurve.x = newCurve.x(1:uniqI,1);
% newCurve.y = newCurve.y(1:uniqI,1);
% newCurve.std = newCurve.std(1:uniqI,1);
% newCurve.stdErr = newCurve.stdErr(1:uniqI,1);
%% plotting results

% Create axes
% axes('Position',[0.13 0.1126 0.775 0.815]);
% box('on');
% hold('all');


%plot raw data and averaged data%
%plot (srtCurve.x, srtCurve.y, 'k.', newCurve.x,newCurve.y, '-ko');

plot (newCurve.x,newCurve.y, '-ko'); hold on;
%plot error bars%
%
% stdErr( length(srtCurve) ) = [];
%
% for i=1: length(strCurve.x)
% stdErr =
%
% end


% stdErr = 10 * rand (1, length(newCurve.x) ); %generate random stdErr


errorbar(newCurve.x, newCurve.y, newCurve.stdErr,'LineStyle','none','Color',[0 0 1]);


%% output

avgCurve = newCurve;


end

% function newCurve = calcStd(uniqI, temp)
%
% end
29 changes: 29 additions & 0 deletions compare_v_th.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
function output = compare_v_th (current_cell)

% current_cell = cell_05;

for i = 1:min (size(current_cell))

sample = current_cell(:,i);

findAPs(sample);
APdata = find_dv_peaks (sample);
AP_th = find_v_th (APdata.APs);

total_th = [];
for j = 1:length (AP_th)
total_th = [total_th; AP_th(j).v];
end

mean_th(i,1) = mean (total_th);
f = find_v_th ({APdata.mean_AP});
mean_th_mAP(i,1) = f.v;
end

output.mean_th = mean_th;
output.mean_th_mAP = mean_th_mAP;

figure; hold on;

plot (output.mean_th, '.'); plot (output.mean_th_mAP, 'r.');
end
Loading

0 comments on commit a54e469

Please sign in to comment.