for loop with different range of number

5 vues (au cours des 30 derniers jours)
salad9996
salad9996 le 29 Nov 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);

Réponse acceptée

Star Strider
Star Strider le 29 Nov 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.

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by