for loop with different range of number

6 ビュー (過去 30 日間)
salad9996
salad9996 2019 年 11 月 29 日
回答済み: Star Strider 2019 年 11 月 29 日
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 Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by