forked from olakiril/Libraries
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmarginalSwap.m
31 lines (25 loc) · 828 Bytes
/
marginalSwap.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
function [xs, ys] = marginalSwap(x, y)
% Swap marginals (averages and conditional)
% x and y are matrices, where each row contains one response trace, i.e.
% if there are 10s with 500ms bins and 10 repetitions, x and y should be
% 10 x 20.
%
% AE 2013-06-04
[trials, bins] = size(x);
% get the ordering of the means for swapping the marginal firing rate
% distributions
[~, ox] = sort(mean(x, 1));
[~, oy] = sort(mean(y, 1));
xs = zeros(trials, bins);
ys = zeros(trials, bins);
for i = 1 : bins
% get the ordering of the conditional distributions
xi = x(:, ox(i));
yi = y(:, oy(i));
[~, oxi] = sort(xi);
[~, oyi] = sort(yi);
% swap both firing rate and conditional distributions while keeping the
% dependency structure
xs(oxi, ox(i)) = yi(oyi);
ys(oyi, oy(i)) = xi(oxi);
end