필터 지우기
필터 지우기

Split cell based upon logical value

조회 수: 7 (최근 30일)
Stephen Thompson
Stephen Thompson 2017년 2월 15일
편집: Stephen23 2017년 2월 15일
I have an n x 5 cell array, the 5th column is a logical (0 or 1).
I want to split this into two separate cells, one for false(0) and one for true (1), preserving the cell structure.
What's the best was of doing this?

답변 (1개)

Kaushik Lakshminarasimhan
Kaushik Lakshminarasimhan 2017년 2월 15일
편집: Stephen23 2017년 2월 15일
You can treat your cell array like a matrix. So if X is your nx5 cell array,
truecells = X([X{:,5}],1:4);
falsecells = X(~[X{:,5}],1:4);
  댓글 수: 3
Kaushik Lakshminarasimhan
Kaushik Lakshminarasimhan 2017년 2월 15일
Sorry I'm not sure what you mean by "won't do anything". That line of code basically splits your original cell array into two cell arrays based on whether the 5th column was true or false.
Stephen23
Stephen23 2017년 2월 15일
편집: Stephen23 2017년 2월 15일
@Stephen Thompson: based on the description in your question, Kaushik Lakshminarasimhan's answer fulfills your needs. What does "won't do anything" actually mean?
truecells = X([X{:,5}],:);
falsecells = X(~[X{:,5}],:);

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by