フィルターのクリア

How to select columns based on a known repeated pattern.

1 回表示 (過去 30 日間)
Matt
Matt 2013 年 12 月 5 日
回答済み: Andrei Bobrov 2013 年 12 月 5 日
I have data that came from excel and I want to grab the data without all the comments. I have imported the data into matlab but now I am having trouble selecting it cleanly. If the data is in a variable called raw I do the following.
data = raw(:,28:22:end);
data = [data, raw(:,29:22:end)];
data = [data, raw(:,30:22:end)];
data = [data, raw(:,31:22:end)];
data = [data, rwa(:,32:22:end)];
The problem with this is I have to reorder everything afterwards to get the columns back in the right order. I want to select all the columns like:
data = raw(:,[28:32]:22:end);
or something similiar. I figure there must be some ultra fancy vector way of doing this in 1 shot.

採用された回答

Andrei Bobrov
Andrei Bobrov 2013 年 12 月 5 日
data = raw(:,bsxfun(@plus,29:32,22*(0:floor((size(raw,2)-32)/22))'));

その他の回答 (2 件)

the cyclist
the cyclist 2013 年 12 月 5 日
One marginally better possibility:
data = raw(:, [28:22:end 29:22:end 30:22:end 31:22:end 32:22:end]);

Kelly Kearney
Kelly Kearney 2013 年 12 月 5 日
Not quite one shot, but a little less typing:
n = size(raw, 2);
idx = bsxfun(@plus, (1:22:n)', 28:32);
idx = idx(idx <= n);
data = raw(:,idx);
  1 件のコメント
Matt
Matt 2013 年 12 月 5 日
2 minor things but this is good.
idx = bsxfun(@plus, (1:22:n)', 27:31);
idx = sort(idx(idx <= n)); % sorts the columns in the right order

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLarge Files and Big Data についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by