How to calculate post-pre connectivity matrices for multiple subjects

2 views (last 30 days)
Hi all,
I am a newbie in MATLAB and desperately need help. I have connectivity matrices (51x51) for 33 subjects for pre_intervention and post_intervention scans.
I would like to group all the 33 pre_intervention matrices and 33 post_intervention matrices, then calculate:
Gnew= Gpost- Gpre
And run a paired t-test.
The filenames are saved in this format: ABC_MS001_post_taskA_connectivity.mat
ABC_MS001_pre_taskA_connectivity.mat
ABC_MS002_post_taskA_connectivity.mat
ABC)MS002_pre_taskA_connectivity.mat
How can I load the concatenated Gpre to be subtracted from the concatenated Gpost .mat files?

Answers (1)

KSSV
KSSV on 2 Aug 2019
Edited: KSSV on 2 Aug 2019
postfiles = dir('*post*.mat') ; m = length(postfiles) ;
prefiles = dir('*pre*.mat') ; n = length(prefiles) ;
post = zeros(51,51,m) ;
pre = zeros(51,51,n) ;
for i = 1:m % as you said both the files are same in number so one loop
load(postfiles(i).name) ;
post(:,:,i) = Gpost ; % name the matrix in the mat file
pre(:,:,i) = Gpre ; % name the matrix in the mat file
end
Gnew= Gpost- Gpre ;

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!