compare and combine matrices
정보
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
이전 댓글 표시
Hi
I have 2 matrices, let's say:
A=[1 2 3; 1 2 3; 1 2 3]
B=[1 2 3; 2 1 3; 3 2 1]
Now i want a matrix C that contains the value in A&B if A = B, and the subtract (A-B)*10 when A and B are different.
I created a matrix
D=A-B
And then I used a for loop with an if command
for t=1:length(A) for l=1:length(A) if D(l,t) == 0 C(l,t)=A(l,t) else C(l,t)=D(l,t)*10 end end end
This works but it takes very long as i have huge matrices; Is there a possibility to avoid the for loop?
Thank you very much in advance
Nina
댓글 수: 0
답변 (1개)
Andrei Bobrov
2016년 2월 3일
편집: Andrei Bobrov
2016년 2월 3일
0 개 추천
C = A; t = A~=B; C(t) = 10*(A(t) - B(t));
댓글 수: 0
이 질문은 마감되었습니다.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!