フィルターのクリア

I need to remove every other 9 rows of a matrix

3 ビュー (過去 30 日間)
Joseph
Joseph 2013 年 6 月 25 日
コメント済み: Massimiliano Tondi 2021 年 3 月 12 日
This should be simple but its giving me some trouble. I have a matrix of 57 rows and 3 columns. This matrix is a condensed set of data from 3 data sets with 19 rows of data each. The first 9 rows of each individual data sets are unneeded and need to be removed. So in the full matrix I need to remove the first 9 rows of data, move down 10 rows, remove the next 9 rows of data, move down another 10 rows, and the remove the next 9 rows of data. Does anyone know how I can do this?

採用された回答

Matthew Eicholtz
Matthew Eicholtz 2013 年 6 月 27 日
How about this?
r = 57; % total rows
c = 3; % total columns
d = 19; % rows in each data set
n = 9; % remove first n rows in each data set
A = cumsum(ones(r,c)); % example data
A(mod(1:r,d)<=n & mod(1:r,d)>0,:) = [];
  3 件のコメント
ADITHYAN
ADITHYAN 2015 年 4 月 22 日
Very elegant answer. Thanks a lot, helped me as well.
Massimiliano Tondi
Massimiliano Tondi 2021 年 3 月 12 日
helped me as well, thanks a lot !

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

その他の回答 (3 件)

Andrei Bobrov
Andrei Bobrov 2013 年 6 月 26 日
編集済み: Andrei Bobrov 2013 年 6 月 27 日
A = randi(100,57,5); % your data
a = 19*ones(size(A,1)/19,1);
A(bsxfun(@plus,cumsum(a) - a + 1,0:8),:) = [];
  2 件のコメント
Joseph
Joseph 2013 年 6 月 26 日
Thank you for your help. This works great for my data set of 57 rows but what if I had an increased data size.So for example say I had a data set of 190 rows or even more. How would I change this to accommodate for additional data? I attempted to run the code for a 190 row set and it didn't quite work.
Andrei Bobrov
Andrei Bobrov 2013 年 6 月 27 日
corrected

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


Jan
Jan 2013 年 6 月 26 日
A = rand(57,5);
s1 = size(A, 1);
index = zeros(1, s1);
index(1:19:s1) = 1;
index(10:19:s1) = -1;
R = A(logical(cumsum(index)), :);
(not tested)

Matt Kindig
Matt Kindig 2013 年 6 月 26 日
編集済み: Matt Kindig 2013 年 6 月 26 日
So, to confirm, you need to do the following:
  • remove rows 1-9 (9 rows)
  • retain rows 10-19 (10 rows)
  • remove rows 20-28 (9 rows)
  • retain rows 29-38 (10 rows)
  • remove rows 39-47 (9 rows)
  • retain rows 48-57 (10 rows)
I think this should do it:
M = [(1:57)', rand(57,2)]; %random data for illustration
npts = size(M,1);
nremove = 9; %number of rows to remove at once
nretain = 10; %number of rows to retain at once
%which removes to remove
removeRows = cell2mat(arrayfun(@(k) k:(k+nremove-1), 1:(nremove+nretain):npts, 'UniformOutput', false));
removeRows(removeRows>npts)=[]; %ignore rows beyond size of M
M(removeRows,:) = []; %remove these rows

カテゴリ

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

製品

Community Treasure Hunt

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

Start Hunting!

Translated by