MATLAB Answers

Multiples traces overlapping on multiple subplots

30 views (last 30 days)
jeanne93
jeanne93 on 3 Feb 2021
Commented: jeanne93 on 4 Feb 2021
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 Comments
jeanne93
jeanne93 on 3 Feb 2021
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?

Sign in to comment.

Accepted Answer

VBBV
VBBV on 3 Feb 2021
Edited: VBBV on 3 Feb 2021
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 Comments

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!