how can i create figures in a for loop

I have to create a figure every 80 measurements of a row vector with length 31999 (Bn in the code). I tried to write this code but i receive only one figure with all the measurements (31999):
k= length(Bn);
for i= 1:80:(k-1)
Bn1(i) = L(i);
plot(Bn1);
end
any suggestion?

 Respuesta aceptada

Star Strider
Star Strider el 5 de Nov. de 2018
Try this:
repts = fix(numel(Bn)/80);
for k1 = 1:repts
figure(k1)
idxrng = (1:80) + 80*(k1-1);
plot(Bn(idxrng), L(idxrng))
grid
end

3 comentarios

Elisa Mammoliti
Elisa Mammoliti el 5 de Nov. de 2018
thank you Star Rider, it works and it gives what i need. Also really thank you to mahdan ravi for the support!!!
Star Strider
Star Strider el 5 de Nov. de 2018
My pleasure.
If my Answer helped you solve your problem, please Accept it!
Something like this could work, creating a cell array of the findchangepts outputs:
repts = fix(numel(Bn)/80);
for k1 = 1:repts
figure(k1)
idxrng = (1:80) + 80*(k1-1);
ipt{k1} = findchangepts(L(idxrng));
plot(Bn(idxrng), L(idxrng))
grid
end
Note: The ‘ipt’ indices would be with respect to each section of ‘L(idxrng)’ not the entire ‘L’ vector. To create that, you would have to add the ‘80*(k1-1)’ offset to each set. If you want to do that, create a second set of vectors with those offsets, then concatenate them into one vector of serial ‘ipt’ values.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.

Preguntada:

el 5 de Nov. de 2018

Comentada:

el 6 de Nov. de 2018

Community Treasure Hunt

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

Start Hunting!

Translated by