offset matrix multiplication with loop

조회 수: 1 (최근 30일)
Emilio  Alverio
Emilio Alverio 2018년 2월 6일
댓글: Emilio Alverio 2018년 2월 8일
Hello,
I have two matrices A(i,j) and B(i,j) where 'i' is row and 'j' is column both of size 1486X41. I am trying to use a loop to multiply the two together such that the first term in each column of A is skipped, I.E. multiply A(2,1) with B(1,1) to give C(1,1) and then A(3,1) with B(2,1) for C(2,1) and so on. The final matrix size will be now 1485X41. I've attempted using a for loop but I struggle with thinking through the code. So far my efforts have led me to:
for i = 1:(length(A)-1)
at = A(i+1)-A(1)
C = B*at
end
I hope my question is clear, and I apologize in advanced for any confusion with the wording. Thank you.

채택된 답변

Jos (10584)
Jos (10584) 2018년 2월 6일
% test data
A = randi(10,3,4)
B = cumsum(ones(size(A)))
% engine
C = A(2:end,:) .* B(1:end-1,:) % C(i,j) = A(i+1,j) * B(i,j)
  댓글 수: 1
Emilio  Alverio
Emilio Alverio 2018년 2월 8일
This worked wonderfully. Thank you for your help!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by