How to multiply each term in a n*n matrix with elements in a column matrix
1 view (last 30 days)
Show older comments
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 Comments
John D'Errico
on 1 Dec 2022
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 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.
Answers (1)
KSSV
on 1 Dec 2022
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
See Also
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!