%cb_centers analysis

ParametersRun500
dataset_positions = [{2,0}; {2,1}; {2,2}; {2,3}; {2,4}; {4,0}; {4,2}; {4,3}; {4,4}; {4,5}; {5,0}; {5,1}; {5,2}; {5,3}; {6,0}; {6,1}; {6,2}; {6,3}; {6,4}; {6,5}; {7,0}; {7,1}; {7,2}; {7,3}; {7,4}; {7,5}; {10,0}; {10,1}; {10,2}; {10,3}; {10,5}];

num_tp = size(dataset_positions,1);
cb_centers_mat = zeros(6,3,num_tp);

for i = 1:size(dataset_positions,1)

    dataset = dataset_positions{i,1}
    position = dataset_positions{i,2}
    
    cb_centers_mat(:,:,i) = cb_centers{dataset,position+1};
end

cb_centers_means = mean(cb_centers_mat,3);
for i = 1:num_tp
    for j = 1:6
        cb_centers_distances(i,j) = norm(cb_centers_mat(j,:,i) - cb_centers_means(j,:));
    end
end

cb_centers_distances = cb_centers_distances;

cb_centers_dist_means = mean(cb_centers_distances,1);
cb_centers_stds = std(cb_centers_distances,1);

for i = 1:6
    this_mat = squeeze(cb_centers_mat(i,:,:));
    these_cb_stds(i,:) = std(this_mat,0,2);
end

n = size(dataset_positions,1);

cb_centers_distances_microns = .1625*cb_centers_distances;
cb_centers_dists_means_microns = mean(cb_centers_distances_microns,1);
cb_centers_dists_stds_microns = std(cb_centers_distances_microns,0,1);
cb_centers_microns_medians = median(cb_centers_distances_microns,1);

main_dists = cb_centers_distances_microns;
means = cb_centers_dists_means_microns;
stds = cb_centers_dists_stds_microns;
medians = cb_centers_microns_medians;

figure;
for graph_ticker = 1:6
    y_vector = (6-graph_ticker+1)*ones(n,1);
    hold on;
    scatter(cb_centers_distances_microns(:,graph_ticker),y_vector,'b.');
end

set(gca,'ytick',1:6)
set(gca,'yticklabel',{'Cell body 6','Cell body 5','Cell body 4','Cell body 3','Cell body 2', 'Cell body 1'})

% hold on; scatterh = scatter(cb_centers_dists_means_microns,[6 5 4 3 2 1]);
% scatterh.MarkerFaceColor = 'red';
% scatterh.SizeData = 16;

scatterref = scatter(main_dists(1,1:6),[6 5 4 3 2 1]);
scatterref.SizeData = 16;
scatterref.MarkerFaceColor = [0 .6 0]

% medians = median(cb_centers_distances_microns,1);

% scattermed = scatter(medians,[6 5 4 3 2 1],['magenta']);

% errorh = errorbar_x(cb_centers_dists_means_microns,1:6,cb_centers_dists_stds_microns,'b.');

axis([0 7 0 7])
set(gca,'XAxisLocation','top')