필터 지우기
필터 지우기

multiplying 2 matrices with difference sizes

조회 수: 3 (최근 30일)
Mnr
Mnr 2015년 12월 15일
댓글: Mnr 2015년 12월 16일
Hello all,
I have a 12x16 matrix, M,
[ 0 0 1 0 0 0 0 -1 0 1 0 0 -1 0 0 0;0 0 0 1 0 0 1 0 0 0 0 0 -1 0 1 0;0 -1 0 0 -1 0 1 0 0 1 0 0 0 0 0 0;0 0 0 1 0 -1 0 0 0 0 1 0 0 1 0 0;0 0 1 0 0 0 0 0 -1 0 0 0 0 0 1 1;1 0 0 0 0 -1 0 0 0 1 0 0 0 0 1 0;0 0 0 1 0 0 0 -1 -1 0 0 -1 0 0 0 0;0 -1 0 0 0 -1 0 0 0 0 0 -1 0 0 0 1;1 0 0 0 0 0 1 0 0 0 0 0 0 1 0 1; 0 0 1 0 -1 0 0 0 0 0 0 -1 0 1 0 0; 0 -1 0 0 0 0 0 0 -1 0 1 0 -1 0 0 0;1 0 0 0 -1 0 0 -1 0 0 1 0 0 0 0 0]
and a 12x4 matrix P,
[0.8033 - 0.5956i -0.4224 - 0.9064i -0.7512 + 0.6600i -0.6502 - 0.7597i; -0.9993 + 0.0363i -0.9690 + 0.2473i 0.8134 + 0.5817i -0.7593 - 0.6507i; 0.6407 + 0.7678i -0.4739 - 0.8806i -0.9973 - 0.0735i 0.3493 + 0.9370i; 0.7352 + 0.6778i 0.9006 + 0.4346i -0.9478 + 0.3189i 0.9575 + 0.2883i;-0.1797 + 0.9837i 0.7638 - 0.6455i 0.6129 + 0.7902i -0.7013 + 0.7129i;0.8619 - 0.5071i -0.9843 + 0.1766i -0.3126 + 0.9499i -0.8056 + 0.5925i;-0.8067 + 0.5910i 0.4202 - 0.9074i 0.7392 - 0.6735i 0.6508 - 0.7592i;-0.8884 - 0.4590i -0.5747 - 0.8183i 0.8557 + 0.5174i 0.5900 - 0.8074i;-0.9836 + 0.1801i -0.3134 + 0.9496i 0.8707 - 0.4919i 0.6079 - 0.7940i; -0.8750 - 0.4841i -0.9497 + 0.3131i -0.8134 - 0.5817i 0.9811 - 0.1937i;-0.3354 + 0.9421i 0.5805 - 0.8143i -0.2518 + 0.9678i -0.8530 + 0.5218i;-0.6454 - 0.7638i -0.9661 + 0.2582i 0.6314 + 0.7755i 0.4847 - 0.8747i]
where the number of columns in P is the same as the number of non-zero elements in each row of M. I would like to multiply each row of M (non-zero elements) with a row of P in a fast way. Can someone help me please? Thank you!

채택된 답변

Roger Stafford
Roger Stafford 2015년 12월 16일
A = M.';
A = (reshape((A(A~=0)),4,12).').*P; % The element-by-element product
This of course depends on each row of M having exactly four nonzero elements. Otherwise you will receive error messages. I assume you meant element-by-element multiplication.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Operating on Diagonal Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by