How can I find maximum value within each columns and and return the entire elements in that column

3 ビュー (過去 30 日間)
Hello,
Here it is my question:
I have follwoing 3*8 matrix:
A =
0.0596 0.0714 0.8181 0.1499 0.9730 0.4538 0.0835 0.3909
0.6820 0.5216 0.8175 0.6596 0.6490 0.4324 0.1332 0.8314
0.0424 0.0967 0.7224 0.5186 0.8003 0.8253 0.1734 0.8034
What I want is finding maximum value of each two consecutive column and returning entire element of that column which includes maximum value. I also must mention that I want to compare two consecutive together and not to rest of columns. For example, I wont compare second column with third one.
Considering my description ad question following matrix B (3*4) would be the answer.
B =
0.0596 0.8181 0.9730 0.3909
0.6820 0.8175 0.6490 0.8314
0.0424 0.7224 0.8003 0.8034
Thank you so much in advance!

採用された回答

Hernia Baby
Hernia Baby 2021 年 2 月 27 日
編集済み: Hernia Baby 2021 年 2 月 27 日
This code seperates A to odd and even elements, and culculates B with logical indexing.
A = [ 0.0596 0.0714 0.8181 0.1499 0.9730 0.4538 0.0835 0.3909;
0.6820 0.5216 0.8175 0.6596 0.6490 0.4324 0.1332 0.8314;
0.0424 0.0967 0.7224 0.5186 0.8003 0.8253 0.1734 0.8034];
A_odd = A(:,1:2:end-1);
A_even =A(:,2:2:end);
B = A_odd .* (A_odd > A_even) +A_even .* (A_even > A_odd)
B =
0.0714 0.8181 0.9730 0.3909
0.6820 0.8175 0.6490 0.8314
0.0967 0.7224 0.8253 0.8034
  6 件のコメント
Hernia Baby
Hernia Baby 2021 年 2 月 27 日
Thank you again! Is it okey with my last answer? If you want to do more, please let me know anything!
Milad Naderloo
Milad Naderloo 2021 年 2 月 27 日
Thank you so much, it is working really good and indeed efficient! :)

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSignal Attributes and Indexing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by