Filter löschen
Filter löschen

MATLAB maximum value under a certain value

17 Ansichten (letzte 30 Tage)
samantha
samantha am 7 Dez. 2022
Bearbeitet: Arif Hoq am 7 Dez. 2022
How do I find the maximum value of a number that is less than a value. For example, max(19,23) gives a max of 23, but how do I find the max if its under 21. So in this case, I want it to give me 19.
I am wanting to find the largest element of possibilities which is greater than or equal to 17, and less than or equal to 21.

Akzeptierte Antwort

Arif Hoq
Arif Hoq am 7 Dez. 2022
Bearbeitet: Arif Hoq am 7 Dez. 2022
a=[ 23, 19, 12,18,30,17,20,28,21,65,22,31];
b=a(a>=17 & a<=21) % elements between greater equal 17 and smaller equal 21
b = 1×5
19 18 17 20 21
maximumelement=max(b) % maximum element
maximumelement = 21

Weitere Antworten (1)

Askic V
Askic V am 7 Dez. 2022
v = 1:20
v = 1×20
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
max_treshold = 15;
b_max = max(v(v < 15))
b_max = 14
This is pretty easy in Matlab.

Kategorien

Mehr zu Shifting and Sorting Matrices 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