multiply table and matrix

조회 수: 7 (최근 30일)
Mo Das
Mo Das 2019년 5월 23일
댓글: Mo Das 2019년 5월 23일
how can i multiply these example?
A= {[0.2 0.5 0.3] [ 0.1 0.1 0.3]}
A=cell2table(A)
B=[ 2 3]
A*B must be {[0.4 1 0.6] [0.3 0.3 0.9]}

채택된 답변

madhan ravi
madhan ravi 2019년 5월 23일
편집: madhan ravi 2019년 5월 23일
I prefer Adam's method :
although if you want to multiply table with matrix then=>
arrayfun(@(x) A{:,x}*B(x),1:numel(B),'un',0)

추가 답변 (1개)

Adam
Adam 2019년 5월 23일
Why all the complications with cell arrays and tables? Just use numeric arrays:
A = [0.2 0.5 0.3; 0.1 0.1 0.3];
B = [2;3];
C = A.* B;
or
C = bsxfun( @times, A, B );
if you have an older version of Matlab.
  댓글 수: 1
Mo Das
Mo Das 2019년 5월 23일
i need to get answer like this {[0.4 1 0.6] [0.3 0.3 0.9]}
but matrix gives me
[0.4 1 0.6
0.3 0.3 0.9]
in first situation i have 2 items and i need 2 items too but in second form i get 6 ones

댓글을 달려면 로그인하십시오.

카테고리

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