for loop with different range of number

5 次查看(过去 30 天)
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);

采纳的回答

Star Strider
Star Strider 2019-11-29
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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by