selecting values between vectors and plot the values

2 ビュー (過去 30 日間)
michael
michael 2021 年 1 月 18 日
編集済み: dpb 2021 年 1 月 19 日
Hi,
I have 4 vectors which are unsorted. All have all same length of 360:
Ax, Bx - Values are real numbes between 0 to 360. Values are increasing / decreasing and with modulu 360.
Ay,By - corrolated to Ax, Bx. real numbes between 0 to 180.
(Best was to describe thos vectors are as single sine with phase shift and/or reversal (i.e. -sin(x) )).
I need to:
  1. find max between Ay, By at given point of x vectors.
  2. plot the max value with appropriate value from Ax or Bx.
What I've though is:
  1. sort Ax, Bx and to find the original order (sorting will provide me the initial value which is close to 0.
  2. based on the indexes of the sorting, find Y=max (Ay(idx_a), By(idx_b))
  3. running in for loop in order to find whether the Y(i) is related to Ay to or By and set X from Ax or Bx.
  4. plot(X,Y)
I think that this is not so elegant solution.
Would be glad to have a proposal for a more elegant one.

回答 (1 件)

dpb
dpb 2021 年 1 月 18 日
編集済み: dpb 2021 年 1 月 19 日
isA=(Ax>Bx);
ABx=Bx; ABx(isA)=Ax(isA);
plot(ABx,max(Ay,By))
  2 件のコメント
michael
michael 2021 年 1 月 19 日
編集済み: michael 2021 年 1 月 19 日
shouldn't ABx(isA)=Bx(isA); be changed to ABx(isA)=Ax(isA);
dpb
dpb 2021 年 1 月 19 日
編集済み: dpb 2021 年 1 月 19 日
Yeah, good catch. Cut 'n pasted, then missed the correction when added subscripts thought was done...codger short term memory ain't what it usta' be... :(

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeAnnotations についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by