how to put output from for-loop for many subjects into one graph when they are all overwriting each other as variables?

2 ビュー (過去 30 日間)
mickey
mickey 2019 年 12 月 29 日
コメント済み: mickey 2019 年 12 月 29 日
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 件のコメント
Stephen23
Stephen23 2019 年 12 月 29 日
編集済み: Stephen23 2019 年 12 月 29 日
"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.
mickey
mickey 2019 年 12 月 29 日
thank you!
so if i wanted to make an output for each forloop run that I then could out into an index, how would I do this?

サインインしてコメントする。

回答 (1 件)

KALYAN ACHARJYA
KALYAN ACHARJYA 2019 年 12 月 29 日
編集済み: KALYAN ACHARJYA 2019 年 12 月 29 日
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
If the outputs are simple scalar (numbers), do prefer array rather than multiple variable names.

カテゴリ

Help Center および File ExchangeBehavior and Psychophysics についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by