Find negative in every n rows

조회 수: 1 (최근 30일)
David du Preez
David du Preez 2017년 5월 12일
댓글: Andrei Bobrov 2017년 5월 15일
I have a 2184 x 14 matrix. In column 1 is the datenum value and in column 14 the values that I want to consider. The other columns contain some other data.
I want to consider the first 24rows if any of the values in column 14 are negative. I want to delete the first 24rows and then repeat this for the following 24rows.

채택된 답변

Andrei Bobrov
Andrei Bobrov 2017년 5월 12일
편집: Andrei Bobrov 2017년 5월 15일
One way
% A - your data [2184 x 14]
ii = ceil((1:size(A,1))'/24);
jj = accumarray(ii,A(:,14),[],@(x)all(x >= 0)); % EDIT
out = A(jj(ii),:);
  댓글 수: 2
David du Preez
David du Preez 2017년 5월 15일
편집: David du Preez 2017년 5월 15일
That does not work. It does not find any negative neither removes them. attached in the matrix in question
Andrei Bobrov
Andrei Bobrov 2017년 5월 15일
I'm fixed my answer.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Jan
Jan 2017년 5월 15일
편집: Jan 2017년 5월 15일
Data = rand(2184, 14) - 0.1; % Test data
D = reshape(Data, 24, [], 14);
Match = any(D(:, :, 14) < 0, 1);
Result = reshape(D(:, Match, :)), [], 14);

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by