cellfunc -multiplication of two cells
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
how to multiply two cells let's say:D = {[1 2 ] , [1 3] ; [1 6] , [5 2] } L={[1],[0],[0],[0];[0],[1],[0],[0]}
I want to do L*D how do I do that? --Thanks
0 Commenti
Risposte (2)
Walter Roberson
il 15 Nov 2013
What answer are you expecting?
L is 2 x 4 with each element 1 x 1, so most likely L should be considered to be like a 2 x 4 matrix.
D is 2 x 2 with each element 1 x 2. One of the ways to view that would be as a 2 x 4 matrix.
But if one views this as a (2 x 4) * (2 x 4) then the "*" operator must fail because the inner dimensions do not agree.
I am going to speculate that you asked the wrong question and that what you want is L .* D
cell2mat(L) .* cell2mat(D)
0 Commenti
sixwwwwww
il 15 Nov 2013
Dear Mihnathul, I completely agree with Walter. Your question is not completely clear, however if you really insist to use cellfun for this purpose then maybe you can try something like this:
if prod(size(L)) >= prod(size(D))
Mat = cellfun(@times, num2cell(reshape(cell2mat(D), size(L, 1), size(L, 2))), L);
else
Mat = cellfun(@times, D, num2cell(reshape(cell2mat(L), size(D, 1), size(D, 2))));
end
disp(Mat)
The code is nothing in itself. Just it is making dimensions of 2 cell arrays equal so that you can use cellfun. I hope it helps. Good luck!
0 Commenti
Vedere anche
Categorie
Scopri di più su GPU Computing in MATLAB in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!