for loop with different range of number

5 visualizaciones (últimos 30 días)
salad9996
salad9996 el 29 de Nov. de 2019
Respondida: Star Strider el 29 de Nov. de 2019
If i have a vector r with 500 numbers, can I use for loop to loop for every 50 number? For example, v1 will get 50 number from r, and v2 will get the next 50 number from r.
vector_r
v1=r(1:50);
v2=r(51:100);
v3=r(101:150);
v4=r(151:200);
v5=r(201:250);
v6=r(251:300);

Respuesta aceptada

Star Strider
Star Strider el 29 de Nov. de 2019
You can use a for loop, however I would do this instead:
r = 1:500; % Create ‘r’ To Test Code
for k = 1:6
v(k,:) = r((1:50)+(50*(k-1)));
end
Experiment to get the result you want.

Más respuestas (0)

Categorías

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

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by