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!
0 件のコメント
採用された回答
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
2021 年 2 月 27 日
Thank you again! Is it okey with my last answer? If you want to do more, please let me know anything!
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!