Indexing sections of arrays
7 ビュー (過去 30 日間)
表示 古いコメント
Mohammed Kagalwala
2019 年 10 月 23 日
コメント済み: Mohammed Kagalwala
2019 年 10 月 23 日
Is there an easy way to extract every section's of n elements of a vector in MATLAB and skip the next n? Say we have
x = linspace(1,10,10); %[1 2 3 4 5 6 7 8 9 10]
I wish to index such that I grab 1,2,3 then skip 4,5,6 and again grab 7,8,9. For example,
a = zeros(1,10); % [0 0 0 0 0 0 0 0 0 0]
a(magic index) = x(magic index)
So now a = [1 2 3 0 0 0 7 8 9 0]
I've only been able to find how to get every nth element but not chunks of n elements.
Thank you for your help in advance !
採用された回答
Jos (10584)
2019 年 10 月 23 日
編集済み: Jos (10584)
2019 年 10 月 23 日
x = 101:110
n = 3
tf = mod(0:numel(x)-1, 2*n) < n
a = zeros(size(x))
a(tf) = x(tf)
index = find(tf)
その他の回答 (0 件)
参考
カテゴリ
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!