How to multiply each term in a n*n matrix with elements in a column matrix

2 次查看(过去 30 天)
I am having a 14*15 matrix and 15*1 matrix. Now, I need to multiply these two matrix. Thank you in advance.
For example:
A=[ 0.34005, 1.15985, -1.42862; 0.45204, -0.12963, -0.07851; 0.18586, -0.49792, 0.56187; 0.20188, 0.19786, -0.54699]
B=[0; 0; 1; 1]
Expected output:
A11 - First row first column, A21 - Second row first column
C=[A11*B2, A21*B3, A31*B4; A12*B1, A22*B3, A32*B4; A13*B1, A23*B2, A33*B4; A14*B1, A24*B2, A34*B3]
C=[0, 1.15985, -1.42862; 0, -0.12963, -0.07851; 0, 0, 0.56187; 0, 0, -0.54699]
  3 个评论
John D'Errico
John D'Errico 2022-12-1
Confusing. You seem to be mixing up rows and columns, sort of randomly. In your words, you talk about a matrix with 14 rows and 15 columns. But your example has more rows than columns in A. But then the way you then show the indexes for A, it has more columns than rows. Perhaps you don't understand how MATLAB treats arrays.
A = reshape(1:12,4,3)
A = 4×3
1 5 9 2 6 10 3 7 11 4 8 12
A is a 4x3 matrix. It has 4 rows, and 3 columns. The FIRST index of A is the row number. The second index refers to the column number. So in MATLAB for this matrix, A(1,2) == 5.
ASHA PON
ASHA PON 2022-12-1
Thank you for your reply. Actually i have explained my problem in a smaller matrix dimension for better understanding.

请先登录,再进行评论。

回答(1 个)

KSSV
KSSV 2022-12-1
A=[ 0.34005, 1.15985, -1.42862; 0.45204, -0.12963, -0.07851; 0.18586, -0.49792, 0.56187; 0.20188, 0.19786, -0.54699] ;
B=[0; 0; 1; 1] ;
% A11 - First row first column, A21 - Second row first column
% C=[A11*B2, A21*B3, A31*B4; A12*B1, A22*B3, A32*B4; A13*B1, A23*B2, A33*B4; A14*B1, A24*B2, A34*B3]
C=[0, 1.15985, -1.42862; 0, -0.12963, -0.07851; 0, 0, 0.56187; 0, 0, -0.54699] ;
b = zeros(length(B)-1) ;
for i = 1:length(B)-1
t = B' ;
t(i) =[] ;
b(i,:) = t ;
end
iwant = A*b

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by