"at most" in MATLAB

조회 수: 3 (최근 30일)
Azam Boskabadi
Azam Boskabadi 2019년 4월 16일
댓글: Azam Boskabadi 2019년 4월 16일
Hey Everyone,
Imagine I have a matrix like 'check'. I want to see if at mostat most one of these three numbers in each columns in 'check' is exactly equal to i or j, my codes run one part of my codes (part two), and otherwise, when 2 out of three number in each column is exacyly equal to i and j run the other part of my code(part one). A small example is like this:
check =
1 4
2 5
3 6
i=2
j=3
Then part one of codes run;
i=5
j=3
run part two.
How can I code that?
Ill really appreciate your help.
i can NOT be equal to j.
Thank you

채택된 답변

Rik
Rik 2019년 4월 16일
This code should help:
check =[1 4;2 5;3 6];
%i=2;j=3;
i=5;j=3;
matches_per_col=sum(check==i | check==j,1);
if max(matches_per_col)==2
disp('part one')
else
disp('part two')
end
  댓글 수: 1
Azam Boskabadi
Azam Boskabadi 2019년 4월 16일
Thank you!!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by