for loop with different range of number

5 Ansichten (letzte 30 Tage)
salad9996
salad9996 am 29 Nov. 2019
Beantwortet: Star Strider am 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);

Akzeptierte Antwort

Star Strider
Star Strider am 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.

Weitere Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by