필터 지우기
필터 지우기

conditional statements on matrices

조회 수: 1 (최근 30일)
puccapearl
puccapearl 2024년 4월 8일
댓글: Voss 2024년 4월 8일
Hi, I have two matrices like below:
I want to search when the 2nd column equals 0 on either matrix and make a new matrix that shows the 0 values along with its paired column 1 values. I also want to tag it to know from which matrix it came from.
Thank you! I am new to conditional statements.

채택된 답변

Voss
Voss 2024년 4월 8일
Where M1 and M2 are your matrices:
idx1 = M1(:,2) == 0;
idx2 = M2(:,2) == 0;
tags = repelem([1; 2],[nnz(idx1) nnz(idx2)]);
result = [[M1(idx1,:); M2(idx2,:)] tags]
  댓글 수: 9
puccapearl
puccapearl 2024년 4월 8일
oh my gosh! *face palm*
Thank you! I'm sorry for the run around!
Voss
Voss 2024년 4월 8일
No problem! You're welcome!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Image Data Workflows에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by