Divide a cell arrays with a part of another cell array
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
gsourop
le 18 Nov 2016
Réponse apportée : Walter Roberson
le 18 Nov 2016
Hi everyone,
I want to divide a cell array A, 2x100 with the last 100 elements of another cell array B 1x101.All of the elements of both cell arrays are scalars. I have tried
c=num2cell(cell2mat(A)./cell2mat(B{1,2:end}));
but it doesn't work. Thanks in advance.
0 commentaires
Réponse acceptée
James Tursa
le 18 Nov 2016
Modifié(e) : James Tursa
le 18 Nov 2016
Try this:
C = num2cell(bsxfun(@rdivide,cell2mat(A),cell2mat(B(1,2:end))));
Note that B{1,2:end} using the curly braces will be a comma-separated-list of the contents of B, whereas B(1,2:end) using parentheses will simply be another cell array.
0 commentaires
Plus de réponses (1)
Walter Roberson
le 18 Nov 2016
c = num2cell( cell2mat(A) ./ repmat( cell2mat(B(1,2:end)), size(A,1), 1) );
If you are using R2016b or later you can
c = num2cell( cell2mat(A) ./ cell2mat(B(1,2:end)) );
which is the same as what you had except it uses B(1,2:end) rather than B{1,2:end}
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!