Replacing some elements in the row with maximum value along the row
이전 댓글 표시
Hi,
I want to replace some elements of each rows in a matrix with the maximum value along the rows.
For example,
A=[1 2 3 0 0;7 4 5 1 0;2 4 6 0 3] to B=[1 2 3 3 3;7 4 5 1 7;2 4 6 6 3]
댓글 수: 3
Scott MacKenzie
2021년 10월 18일
Your question is too vague. Please give gave an example of what you are trying to do.
Rajesh
2021년 10월 18일
Scott MacKenzie
2021년 10월 18일
Yes, I see now. I didn't realize that B was your example result. Just posted an answer.
답변 (1개)
There might be a simpler solution, but this seems to work:
A=[1 2 3 0 0; 7 4 5 1 0; 2 4 6 0 3]
for i=1:size(A,1)
A(i,A(i,:)==0) = max(A(i,:));
end
B = A
카테고리
도움말 센터 및 File Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!