"at most" in MATLAB

1 vue (au cours des 30 derniers jours)
Azam Boskabadi
Azam Boskabadi le 16 Avr 2019
Commenté : Azam Boskabadi le 16 Avr 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

Réponse acceptée

Rik
Rik le 16 Avr 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
  1 commentaire
Azam Boskabadi
Azam Boskabadi le 16 Avr 2019
Thank you!!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Characters and Strings dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by