Subtract matrices in an array 'A' with elements from matrix 'B'
2 次查看(过去 30 天)
显示 更早的评论
I have a 1x27 cell array 'A' containing 27 [56x2] doubles. I also have a 27x2 matrix 'B'. I want to subtract all the elements from A{1} with B(1,:) and A{2} with B(2,:) and so on. How do I write a for loop for this?
0 个评论
采纳的回答
更多回答(2 个)
Walter Roberson
2021-3-11
%generate A and B for demo
A = arrayfun(@(idx) rand(56,2), 1:27, 'uniform', 0)
B = rand(27,2)
%now for the work
C = cellfun(@(a,b) a-b, A, num2cell(B, 2).', 'uniform', 0)
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!