Multiples traces overlapping on multiple subplots

Hello! I am struggling to create 16 2D subplots based on data in a matrix 16x800x40, which correspond to 16=conditions, 800=bins (points to be included in each trace), 40=repetitions of the same condition. I want to make 40 different traces, all on one of the 16th subplot (so 16 plots, each having 40 traces on). I know I probably need to create some nested for loop but so far could not work it out.
Would appreciate any help!!
this is what I've tried so far....
for s=1:size(singleTrialTraces,3)
for k=1:size(singleTrialTraces,1)
subplot(4,4,k)
plot(singleTrialTraces(k,:,s))
axis tight
hold on
end
end

2 件のコメント

dpb
dpb 2021 年 2 月 3 日
You're missing a hold on to put additional traces on the given axes.
If you were to orient so each 2D array were a plane in the 3D array, then a slice by 40 columns of 800 rows could be done in one call to plot(); it treats each column in a "y" 2D array as a variable automagically.
jeanne93
jeanne93 2021 年 2 月 3 日
I think I did put 'hold on', didn't I? Should it be somewhere else? :)
Hmmm, I'm sorry, I'm still lost, could you please explain a bit more? what should I put in the plot() command then? Right now I put 3 variables, which isn't correct... how to do this slicing by 40 cols of 800rows here?

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

 採用された回答

VBBV
VBBV 2021 年 2 月 3 日
編集済み: VBBV 2021 年 2 月 3 日

1 投票

clear
clc
K = rand(16,800,40);
for i = 1:16
subplot(16,1,i) % subplot(4,4,i)
for j = 1:40
plot(K(i,:,j),'b-','linewidth',0.2);
ylim([-1 2.5])
hold on
end
end
Try this

6 件のコメント

VBBV
VBBV 2021 年 2 月 3 日
You can try with
subplot(4,4,i)
jeanne93
jeanne93 2021 年 2 月 3 日
Thank you :))
jeanne93
jeanne93 2021 年 2 月 3 日
just one quick thing for clarity - if i was about to superimpose a mean trace for each of these, do i just need to continue and add another plot command after 'hold on'?
VBBV
VBBV 2021 年 2 月 4 日
yes,
VBBV
VBBV 2021 年 2 月 4 日
clear
clc
K = rand(16,800,40);
for i = 1:16
for k = 1:800
KK(i,:) = K(i,k,:);
end
end
for i = 1:16
subplot(4,4,i)
for j = 1:40
plot(K(i,:,j),'-');
hold on
end
hold on
kx = mean(KK(i,:))
kxx = repmat(kx,800,1)
plot(kxx,'k-','linewidth',3)
end
But you may need to put hold on outside of loop as above
jeanne93
jeanne93 2021 年 2 月 4 日
Lovely, thanks so much!

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeBehavior and Psychophysics についてさらに検索

質問済み:

2021 年 2 月 3 日

コメント済み:

2021 年 2 月 4 日

Community Treasure Hunt

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

Start Hunting!

Translated by