Split a vector sequentially into parts provided specified length

5 ビュー (過去 30 日間)
Bolin
Bolin 2018 年 6 月 22 日
編集済み: Matt J 2018 年 6 月 22 日
For example, I have a vector
x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
I have another vector n
n =[2, 2, 3, 3]
I wish to run a FOR loop to obtain,
x = [1, 2] x = [3, 4] x = [5, 6, 7] x = [8, 9, 10]
Suppose n was:
n =[1, 2, 3, 4]
Then my FOR loop should return
x =[1] x = [2, 3] x = [4, 5, 6] x = [7, 8, 9, 10]
How can this be done?

回答 (1 件)

Matt J
Matt J 2018 年 6 月 22 日
編集済み: Matt J 2018 年 6 月 22 日
output = mat2cell(x,1,n)

カテゴリ

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