How to extract parts of an array by given logical conditions?

조회 수: 5 (최근 30일)
Hi, I have an array, let's say
M=
1 1 0
1 2 0
1 3 1
2 1 0
2 2 1
2 3 1
and I would like to create a new array only with the case for which the value of the third column equals 1. Thus
N=
1 3 1
2 2 1
2 3 1

채택된 답변

Image Analyst
Image Analyst 2014년 6월 9일
Try this:
M=[...
1 1 0
1 2 0
1 3 1
2 1 0
2 2 1
2 3 1]
rowsToExtract = M(:,3)==1;
N = M(rowsToExtract,:)
  댓글 수: 1
Emerson De Souza
Emerson De Souza 2014년 6월 9일
Thank you Image Analyst,
your suggestion elegantly solved my problem.
Wish you a nice day
Emerson

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Distribution Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by