Filter löschen
Filter löschen

I have an array and I want to check if any of the array elements doesn't satisfy a certain condition.

1 Ansicht (letzte 30 Tage)
I have an array and I want to check if any of the array elements doesn't satisfy a certain condition.
For example:
A = [ 5 8 1 2 7 9 6]
and I want to find out the number of elements below 3, which are 1 and 2 in this situation, how can i find it for larger arrays?

Akzeptierte Antwort

Jan
Jan am 11 Nov. 2021
A = [ 5 8 1 2 7 9 6];
isLowerThan3 = A < 3
A(isLowerThan3)
  2 Kommentare
Omar N
Omar N am 11 Nov. 2021
Thank you, but this returns it as an array while i need to be an exact number like for the example I have mentioned I need to get isLowerThan3 = 2.
Jan
Jan am 11 Nov. 2021
I do not understand the problem. If you want the numbers smaller than 3, [1, 2] is the correct answer. Why do you want the 2 only? Are you looking for the largest number smaller than 3? Or the number which is nearest to 3?

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by