Compare two columns under 3 conditions
이전 댓글 표시
Hi,
I an array (phases) with two vector of the same lenght. I need to compare the two vectors under the following conditios:
phases(:,1) phases(:, 2)
1................................. 2
1................................. 2
1................................. 2
2................................. 2
2................................. 2
2................................. 1
2................................. 1
2................................. 1
2................................. 1
1................................. 1
1................................. 1
1................................. 1
condition 1: I want to know the number of times phases(:,1) and phases(:, 2) are both 2 in the same row. In this case, there are 2 times.
condition 2: I want to know the number of times phases(:, 2) is equals to 2 when phases(:,1) is equals to 1 in the same row. In this case, there are 3 times.
condition 3: I want to know the number of times phases(:, 1) is equals to 2 when phases(:, 2) is equals to 1 in the same row. In this case, there are 4 times.
Thank you!
댓글 수: 3
madhan ravi
2019년 4월 2일
your 2nd & 3rd conditions are the same?
Francisco Anaya
2019년 4월 2일
Francisco Anaya
2019년 4월 2일
답변 (1개)
Shunichi Kusano
2019년 4월 2일
The following code counts the number of rows which meet the condition 2.
nnz(phases(:,2) == 2 & phases(:,1) == 1)
hope this helps.
카테고리
도움말 센터 및 File Exchange에서 Array Geometries and Analysis에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!