필터 지우기
필터 지우기

cellfunc -multiplication of two cells

조회 수: 3 (최근 30일)
RoboKid
RoboKid 2013년 11월 15일
답변: sixwwwwww 2013년 11월 15일
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

답변 (2개)

Walter Roberson
Walter Roberson 2013년 11월 15일
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)

sixwwwwww
sixwwwwww 2013년 11월 15일
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!

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by