Verifying an Vector composition

1 vue (au cours des 30 derniers jours)
Vinay Killamsetty
Vinay Killamsetty le 20 Juin 2021
If I am having a symmetric structures vector Eg: A = [a2 a1 a3 a4 a5 a4 a3 a2 a1]
I want to check whether the vector is having a peak value at the center index and the other values are arranged in a decreasing fashion from the center. I.e. a1<a2<a3<a4<a5.
How to check this?

Réponse acceptée

Matt J
Matt J le 20 Juin 2021
Modifié(e) : Matt J le 20 Juin 2021
issorted(A(1:ceil(end/2))) & all(A==flip(A))
  1 commentaire
Vinay Killamsetty
Vinay Killamsetty le 22 Juin 2021
Thank you very much

Connectez-vous pour commenter.

Plus de réponses (1)

Scott MacKenzie
Scott MacKenzie le 20 Juin 2021
Modifié(e) : Scott MacKenzie le 22 Juin 2021
There is probably an easier approach, but I think this works. The result of this expression is 1 if a1<a2<a3<a4<a5, or 0 otherwise
mean(diff(A(1:ceil(end/2))) > 0) == 1

Catégories

En savoir plus sur Shifting and Sorting Matrices dans Help Center et File Exchange

Produits


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by