Verifying an Vector composition

조회 수: 1 (최근 30일)
Vinay Killamsetty
Vinay Killamsetty 2021년 6월 20일
편집: Scott MacKenzie 2021년 6월 22일
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?

채택된 답변

Matt J
Matt J 2021년 6월 20일
편집: Matt J 2021년 6월 20일
issorted(A(1:ceil(end/2))) & all(A==flip(A))

추가 답변 (1개)

Scott MacKenzie
Scott MacKenzie 2021년 6월 20일
편집: Scott MacKenzie 2021년 6월 22일
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

카테고리

Help CenterFile Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기

태그

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by