how to put output from for-loop for many subjects into one graph when they are all overwriting each other as variables?
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello!
I have many subjects that have cortex, ventricle, and spinal cord timeseries information in their folders. I am using a for-loop to analyze each individual subject. I now want to do group analysis, and I want to put all of the timeseries in one graph. However, all the variables are currently the same for every subject, and are being overwritten during the for-loop code running. Is there an elegant way to combine all of the timeseries information without having to compeltely rewrite my code? Or a way to make each for loop have a specific detrended output with a number associated with it?
%% adding current path and subfolders
addpath(genpath(pwd))
%defining subjects
subj = {'HCA1','HCA2','HCA3','HCA4'}; %HCPsubj list
%% loading paths and such
D = '/Users/ll/Documents/data_analysis/HCP/seventy/';
for k = 1:length(subj)
name = subj{k};
l = load(fullfile(D,name,'ts','lcortex_run01regPA.txt'));
v = load(fullfile(D,name,'ts','ventricle_run01regPA.txt'));
s = load(fullfile(D,name,'ts','spinal_run01regPA.txt'));
%% defining some variables
c_ts = l
v_ts = v
s_ts = s
%% detrend ventricle and cortex
d_v_ts = detrend(v_ts) %detrended time series of ventricle
d_c_ts = detrend(c_ts) %detrended time series of cortex
d_s_ts = detrend(s_ts) %detrended time series of spinal cord
%% defining timeseries x axis - plotting ventricle, cortex, spinal cord -raw fmri signal
whole_ts = 1:478 %your ventricle timeseries
ttt = whole_ts*.800 %the TR found from HCP mri_info
figure;
ax1 = subplot(3,1,1)
hold on
plot (ttt, d_v_ts)
plot (ttt, d_c_ts)
plot (ttt, d_s_ts)
hold off
legend('ventricle','cortex','spinal cord')
sgtitle(name)
xlabel('Time')
ylabel('Raw fMRI signal')
2 commentaires
Stephen23
le 29 Déc 2019
Modifié(e) : Stephen23
le 29 Déc 2019
"Is there an elegant way to combine all of the timeseries information..."
Of course: it is called indexing.
"Or a way to make each for loop have a specific detrended output with a number associated with it?"
You just described indexing.
Indexing is simple, neat, easy to debug, and very efficient. You should use indexing.
Réponses (1)
KALYAN ACHARJYA
le 29 Déc 2019
Modifié(e) : KALYAN ACHARJYA
le 29 Déc 2019
how to put output from for-loop for many subjects into one graph when they are all overwriting each other as variables?
if outputs are files/any dimension vector/any other forms, do prefer cell array
0 commentaires
Voir également
Catégories
En savoir plus sur Behavior and Psychophysics dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!