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!