"at most" in MATLAB

3 Ansichten (letzte 30 Tage)
Azam Boskabadi
Azam Boskabadi am 16 Apr. 2019
Kommentiert: Azam Boskabadi am 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

Akzeptierte Antwort

Rik
Rik am 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

Weitere Antworten (0)

Kategorien

Mehr zu Characters and Strings finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by