Hello,
I would like to substract 2 matrix of different size ex: A=[1 2 3], B =[4 5] and I want each element of A to be substract by each element of B.
So that the result would be C= 'A-B'=[-3 -4 -2 - 3 -1 -2]
And I want to avoid using For loops, to get it as fast as possible (my A and B are already large).
I could use kron(A, ones(length(B),1)-kron(ones(length(A),1),B). But is there a faster/easier way ?
Thanks,
Bina

 채택된 답변

David Hill
David Hill 2021년 3월 24일

0 개 추천

C=A-B';
C=C(:)';

댓글 수: 1

Binabik
Binabik 2021년 3월 24일
true, then I will have to reshape to have only one 'column'...
I should have thought about it ! gg

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

추가 답변 (0개)

카테고리

도움말 센터 및 File Exchange에서 Weather and Atmospheric Science에 대해 자세히 알아보기

질문:

2021년 3월 24일

댓글:

2021년 3월 24일

Community Treasure Hunt

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

Start Hunting!

Translated by