"at most" in MATLAB

3 visualizzazioni (ultimi 30 giorni)
Azam Boskabadi
Azam Boskabadi il 16 Apr 2019
Commentato: Azam Boskabadi il 16 Apr 2019
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

Risposta accettata

Rik
Rik il 16 Apr 2019
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

Più risposte (0)

Categorie

Scopri di più su Characters and Strings in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by