offset matrix multiplication with loop
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
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)
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!