Compare rows from different columns

조회 수: 3 (최근 30일)
Scott Dean Seedell
Scott Dean Seedell 2024년 2월 17일
답변: Star Strider 2024년 2월 17일
I'm sure this isn't difficult but my brain is struggling a little:
I want to compare two column vectors and see if any of the values in the 1st are larger than any of the corresponding values in the 2nd.
For instance, if row 8 is larger in the 2nd column than the 1st.
Or if row 6 is larger in the 2nd column than the 1st.

채택된 답변

Star Strider
Star Strider 2024년 2월 17일
One approach —
A = randi(50,10,2)
A = 10×2
50 1 2 25 44 38 48 14 46 12 42 9 2 28 4 13 34 18 2 2
Col_2_Larger = A(:,2) > A(:,1)
Col_2_Larger = 10×1 logical array
0 1 0 0 0 0 1 1 0 0
ColNr = find(Col_2_Larger);
fprintf('Col 2 larger in row %d\n', ColNr)
Col 2 larger in row 2 Col 2 larger in row 7 Col 2 larger in row 8
.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Other Formats에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by