Subtract matrices in an array 'A' with elements from matrix 'B'
17 ビュー (過去 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 件)
KSSV
2021 年 3 月 11 日
iwant = cell(size(A));
for i = 1:length(A)
iwant{i} = A{i}-B(i,:) ;
end
0 件のコメント
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 で Creating and Concatenating Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!