Subtract matrices in an array 'A' with elements from matrix 'B'
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Leeba Chacko
le 11 Mar 2021
Réponse apportée : Leeba Chacko
le 11 Mar 2021
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 commentaires
Réponse acceptée
Plus de réponses (2)
KSSV
le 11 Mar 2021
iwant = cell(size(A));
for i = 1:length(A)
iwant{i} = A{i}-B(i,:) ;
end
0 commentaires
Walter Roberson
le 11 Mar 2021
%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 commentaires
Voir également
Catégories
En savoir plus sur Matrices and Arrays dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!