Effacer les filtres
Effacer les filtres

Conditional find in matlab

4 vues (au cours des 30 derniers jours)
Amir Mahmoudi
Amir Mahmoudi le 18 Jan 2024
Commenté : Les Beckham le 18 Jan 2024
I = find(X == a,1,'first'), J = find(X == b,1,'first'), K = find(X == c,1,'first') provided that K > J > I How can I implement the conditional part? Thanks in advance.

Réponse acceptée

Les Beckham
Les Beckham le 18 Jan 2024
Modifié(e) : Les Beckham le 18 Jan 2024
X = [10 20 30 40 50 10 20 30 40 50];
a = 30;
b = 20;
I = find(X == a, 1, 'first')
I = 3
J = find(X((I+1):end) == b, 1, 'first') + I % start search after index I
J = 7
X(I)
ans = 30
X(J)
ans = 20
  2 commentaires
Amir Mahmoudi
Amir Mahmoudi le 18 Jan 2024
Is it possible to write your codes in terms of > or < ?
Les Beckham
Les Beckham le 18 Jan 2024
Sure, just change the == to whatever you want instead.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by