Putting subplots into a for loop?

5 visualizaciones (últimos 30 días)
Maria Y
Maria Y el 25 de Mzo. de 2019
Comentada: Walter Roberson el 30 de Mzo. de 2019
Hello,
I'm looking to put these subplots into a for loop (I just provided the first 3 as an example but there are 7 total).
key1_ind_block1 = SRTT.RT(find(SRTT.Correct_Key(1:100)==1));
subplot(7,1,1)
plot(key1_ind_block1,'-o')
title('Block 1')
xlabel('Number of appearances')
ylabel('Reaction Time')
xlim([0 30])
key1_ind_block2 = SRTT.RT(find(SRTT.Correct_Key(101:200)==1));
subplot(7,1,2)
plot(key1_ind_block2,'-o')
title('Block 2')
xlabel('Number of appearances')
ylabel('Reaction Time')
xlim([0 30])
key1_ind_block3 = SRTT.RT(find(SRTT.Correct_Key(201:300)==1));
subplot(7,1,3)
plot(key1_ind_block3,'-o')
title('Block 3')
xlabel('Number of appearances')
ylabel('Reaction Time')
xlim([0 30])
I started with something like this but I know I'm missing something and it's giving me the error: "Error using find. Second argument must be a positive scalar integer."
for k = 1:7
subplot(7,1,k);
plot(SRTT.RT(find(SRTT.Correct_Key((1 + (k-1)*100):k * 100),'-o')));
end
If someone could provide help it would be much appreciated! (I'm newer to Matlab so let me know if you need more info).
Thanks in advanced.

Respuestas (1)

Walter Roberson
Walter Roberson el 26 de Mzo. de 2019
plot(SRTT.RT(find(SRTT.Correct_Key((1 + (k-1)*100):k*100))), '-o')
  6 comentarios
Maria Y
Maria Y el 26 de Mzo. de 2019
It seems like I got it working with this:
nkeys=SRTT.RT(find(SRTT.Correct_Key));
for k = 1:7
subplot(7,1,k);
plot(nkeys((1 + (k-1)*100):k*100), '-o');
end
Except my xaxis is 0-100 for every subplot instead of increasing to 101-200, 201-300, etc. Is there a way to add this in to the loop?
I appreciate your time helping me.
Walter Roberson
Walter Roberson el 30 de Mzo. de 2019
idx = 1 + (k-1)*100 : k*100;
plot(idx, nkeys(idx), '-o')

Iniciar sesión para comentar.

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by