Matrix syntax error question

조회 수: 6 (최근 30일)
Luke Blades
Luke Blades 2016년 4월 18일
댓글: Guillaume 2016년 4월 18일
Hello,
I have 2 matrices 500 x 500, A and B.
I want to replace all values within A which are larger than the corresponding values in B WITH the value in B. Hope that makes sense!
I've tried
A(A>B) = B
But i get the error:
"In an assignment A(I) = B, the number of elements in B and I must be the same."
Do I have my syntax wrong? The two matrices are definitely both 500 x 500.
Many thanks,
Luke Blades

채택된 답변

Fangjun Jiang
Fangjun Jiang 2016년 4월 18일
index=A>B;
A(index)=B(index);
  댓글 수: 1
Guillaume
Guillaume 2016년 4월 18일
Yes, what you're missing is a filter on B. As a one liner:
A(A > B) = B(A > B);

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Performance and Memory에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by