필터 지우기
필터 지우기

Creating a conditional vector

조회 수: 2 (최근 30일)
Andres Serrano
Andres Serrano 2018년 11월 1일
댓글: Andres Serrano 2018년 11월 1일
Hi guys, I just have this matrix: 0010-0111-0101-1101..... and I want to create a vector with the following condition: if sum of columns 1 and 2 >=1 AND if sum of columns 3 and 4=>1 then column 5=1, otherwise column 5= 0.

채택된 답변

Stephen23
Stephen23 2018년 11월 1일
편집: Stephen23 2018년 11월 1일
Do NOT use a loop for this!
>> a = [0,0,1,0;0,1,1,1;0,1,0,1;1,1,0,1]
a =
0 0 1 0
0 1 1 1
0 1 0 1
1 1 0 1
>> a(:,5) = sum(a(:,1:2),2)>=1 & sum(a(:,3:4),2)>=1
a =
0 0 1 0 0
0 1 1 1 1
0 1 0 1 1
1 1 0 1 1
  댓글 수: 1
Andres Serrano
Andres Serrano 2018년 11월 1일
thanks Stephen, it worked perfectly!

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

추가 답변 (0개)

카테고리

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