to select consecutive more than one column in matlab having difference

1 回表示 (過去 30 日間)
Safi ullah
Safi ullah 2017 年 2 月 26 日
編集済み: Stephen23 2017 年 2 月 26 日
Hello everyboby, I have a matrix named eta=54×1800.for selecting specific rows and columns typically we used e.g result=eta(:, 86:90:1800); But here I need to select consecutive 5 columns 86,87,88,89,90 each having difference 90, e.g after 86,87,88,89,90 I want to get 176,177,178,179,180.I try like result=eta(:,[86:90:1800,87:90:1800,88:90:1800,89:90:1800,90:90:1800]); but it does not give the result of consecutive columns.

採用された回答

Stephen23
Stephen23 2017 年 2 月 26 日
編集済み: Stephen23 2017 年 2 月 26 日
Sort the indices to get consecutive columns adjacent to each other:
idx = sort([86:90:1800,87:90:1800,88:90:1800,89:90:1800,90:90:1800])
eta(:,idx)
Or without having to write that long list:
>> vec = 86:90;
>> C = arrayfun(@(b)b:90:1800, vec, 'Uni',0);
>> idx = sort([C{:}])
or generate them in the correct order in the first place:
>> vec = 86:90;
>> idx = bsxfun(@plus,vec(:),0:90:1800-90);
>> idx = idx(:).'

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDiscrete Math についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by