Concatenate multiple sessions in ttest2

Hello! I am a über-beginner, so please excuse my lack of proper MATLAB nomenclature!
I am trying to create a matrix using ttest2 — a 20x1 to be exact — to assess the significance between number of trials and neuronal firing rate differences before and after stimulus onset. I am having difficulty extracting the data out as such.
The script is written in a series of for loops, but for some reason, I can type 'E' (first variable of interest) in the command window (without running the whole script) and it returns all values (a 20x1 matrix), but when I type 'difftot,' it gives me the last value after it cycled through the for loop. I would like the 20 incidences of this second variable of interest for 'E' stimulus events, again a 20x1 matrix.
Why are these outputs so different? As is, the ttest2 is, of course, only giving me one value.
I ran the script to see if that would remedy the situation, and it returned a lot of variables in the workspace to be '[]' instead of their (row x column) dimensions. And I received the error message that concatenation cannot happen because, of course, the matrices are not the same size.
My script is below; thank you in advance for any help!!!
clear all; close all tic file='/Users/ellenm.walker/Desktop/Lab matters/Maier Lab/MULTISENSORY/'; fileID=fopen('/Users/ellenm.walker/Desktop/Lab matters/Maier Lab/MULTISENSORY/PlasticityInfo.txt'); info=textscan(fileID,'%s%s%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f%f'); fclose(fileID); count=0; all_firing=[]; for ff=1:length(info{1}) animal=info{1}{ff}; this_path=strcat('/Users/ellenm.walker/Desktop/Lab matters/Maier Lab/MULTISENSORY/',animal,'/'); session=strcat(info{2}{ff},'/'); rcds=info{5}(ff); probetype=info{8}(ff); nchan=info{9}(ff); fs=info{10}(ff); sodr=info{16}(ff); wodr=info{17}(ff); isi_threshold=2; plt=0; tst=[0 11 13 6 2]; % tst=pump fluids % 0=water; 11=MV; 13=2H; 6=saccharin; 2=sodium chloride [spike_ts_merge,waves_merge,mua_ts,mua_waves]=Merge(this_path,session,probetype,nchan,fs,isi_threshold,plt); [evt_ts,evt_id]=GetEventsComplete(this_path,session,tst,[],1,0);
pre=1:1000;
post=1001:3000;
total=1:3000;
pre_scalar=1000;
post_scalar=3000;
nunit=0;
format shortG;
for ii=1:length(spike_ts_merge)
if ~isempty(spike_ts_merge{ii})
units=unique(spike_ts_merge{ii}(:,2));
nunit=nunit+1;
for jj=1:length(units)
idx=find(spike_ts_merge{ii}(:,2)==units(jj));
spkbin=GetSpkbin(spike_ts_merge{ii}(idx,1),evt_ts,pre_scalar,post_scalar);
%get odor trial info
A=find((evt_id(:,1)==0) & ((evt_id(:,2)==wodr)));
B=find((evt_id(:,1)==0) & ((evt_id(:,2)==sodr)));
C=find((evt_id(A:2)==sodr));
D=find((evt_id(:,2)==wodr));
E=find((evt_id(:,1)==0) & ((evt_id(:,2)>0)));
odras=evt_id(E,2);
E(find(odras==sodr),2)=1;
E(find(odras==wodr),2)=0;
E(find(odras==sodr),3)=13;
E(find(odras==wodr),3)=11;
%plot responses
% figure;
% %plot neutral odor trials
M=mean(spkbin(A,:));
N=mean(spkbin(B,:));
sm=smooth(M,500,'lowess');
sm2=smooth(N,500,'lowess');
% plot(sm,'g');
% hold on
% plot(sm2,'r');
% legend('MV','2H');
% title({animal;session});
count=count+1;
prewtr=mean(M(pre));
postwtr=mean(M(post));
presac=mean(N(pre));
postsac=mean(N(post));
diffwtr=postwtr-prewtr;
diffsac=postsac-presac;
difftot=(postwtr+postsac)-(prewtr+presac);
%alldata(count,1)=animal;
alldata(count,2)=mean(rcds);
alldata(count,3)=mean(prewtr);
alldata(count,4)=mean(postwtr);
alldata(count,5)=mean(diffwtr);
alldata(count,6)=mean(presac);
alldata(count,7)=mean(postsac);
alldata(count,8)=mean(diffsac);
all_firing(count,:)=[mean([M;N])];
%h=ttest2=(for all 20 trials, df in firing rate (post-pre)) -- look if df firing rates are different from 0
% h=ttest2(E,diffwtr);
% h=ttest2(E,diffsac);
h=ttest2(E,difftot)
end
end
end
end
toc

Answers (0)

This question is closed.

Asked:

on 3 Oct 2018

Closed:

on 3 Oct 2018

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!