Swapping elements from one matrix to another.
조회 수: 3 (최근 30일)
이전 댓글 표시
Hi all. I am relatively new in Matlab.
Suppose i have two matrices A= [1 2 3 -4 5 -6 8 9 10 -5 -4 -2]' and B=[12 2 3 4 5 6 -7 9 6 4 5 -1]'. Both of them are of the same order.
I want to replace the negative values in A with the corresponding values of B( the same index values).
Expected updated A = [1 2 3 4 5 6 8 9 10 4 5 -1]'.
Kindly help.
댓글 수: 1
Jintao Wu
2020년 3월 2일
I am also new here .Now let me exchange something about the MATLAB . You can do it like this ,
[a1,a2]=find(A<0);
A[a1,a2]=B[a1,a2];
You can use the 'find' function . After that , you can try it to complete the similar issues .
Congratulations
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!