How can I find maximum value within each columns and and return the entire elements in that column
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Milad Naderloo
el 27 de Feb. de 2021
Comentada: Milad Naderloo
el 27 de Feb. de 2021
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 comentarios
Respuesta aceptada
Hernia Baby
el 27 de Feb. de 2021
Editada: Hernia Baby
el 27 de Feb. de 2021
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 comentarios
Hernia Baby
el 27 de Feb. de 2021
Thank you again! Is it okey with my last answer? If you want to do more, please let me know anything!
Más respuestas (0)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!