필터 지우기
필터 지우기

How do I eliminated the first negative element?

조회 수: 1 (최근 30일)
Francesco
Francesco 2014년 3월 1일
댓글: Francesco 2014년 3월 1일
With this variable:
A =
Columns 1 through 4
[1000x9 double] [1000x9 double] [1000x9 double] [1000x9 double]
Columns 5 through 8
[1000x9 double] [1000x9 double] [1000x9 double] [1000x9 double]
My issue is to by-pass (or not consider) the rows that start with a negative number in the first column. I want treat the 8 different arrays as independent ones with regards to ignoring rows that start with a negative number in the first column?. As anyone have an idea?
  댓글 수: 1
the cyclist
the cyclist 2014년 3월 1일
Just to clarify a couple things:
  • When you say "bypass", "not consider" or "ignore", do you mean you want to delete those rows, or something else?
  • A is a 1x8 cell array, each cell is a matrix of doubles, right?

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

채택된 답변

the cyclist
the cyclist 2014년 3월 1일
편집: the cyclist 2014년 3월 1일
Assuming you want to delete the rows in which the first column is negative, then this should do the trick:
% Fill in some fake data
A = cell(1,8);
for i = 1:8
A{i} = rand(1000,9) - 0.5;
end
% Create a cell array where the matrices have the leading-negative rows deleted
B = cellfun(@(x) x(x(:,1)>=0,:), A, 'UniformOutput', false)
  댓글 수: 3
the cyclist
the cyclist 2014년 3월 1일
The first part of that code was just to create some fake data that had some rows starting with positive and some negative.
Francesco
Francesco 2014년 3월 1일
Ok, thanks! Your line of code run well!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by