"at most" in MATLAB

3 次查看(过去 30 天)
Azam Boskabadi
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

更多回答(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