offset matrix multiplication with loop
1 view (last 30 days)
Show older comments
Emilio Alverio
on 6 Feb 2018
Commented: Emilio Alverio
on 8 Feb 2018
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.
0 Comments
Accepted Answer
Jos (10584)
on 6 Feb 2018
% 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)
More Answers (0)
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!