Multiplicación de varias columnas por una matriz

2 views (last 30 days)
Hola,
yo tengo una matriz A
A=[1 2 3 4
5 6 7 8
1 2 3 4
8 7 6 5]
Y tengo otra de
B=[1 1 1 1 1
2 3 4 4 4
3 2 2 2 2
4 1 1 3 3]
Y quiero multiplicar cada columna de B (que en realidad es de n columnas) por la matriz A, y obtener en una matriz en cada columna los resultados, lo que tengo es lo siguiente y me sale error.
C=zeros(size(A,1),length(B));
for o=1:size(A,1)
C(o,size(B,2))=A*(B(:,o));
end

Accepted Answer

Geoff Hayes
Geoff Hayes on 23 Apr 2020
Isabel - try the following
C = zeros(size(A,1),size(B,2)); % <--- (number or rows of A) x (number of columns of B)
for o=1:size(B,2) % <--- iterate over each column of B
C(:,o)=A*(B(:,o)); % <--- use : C(:,o) means to set all rows of oth column
end
Note that
C(o,size(B,2))=A*(B(:,o));
is equivalent to
C(o,5))=A*(B(:,o));
so the code is trying to assign a 4x1 column to a single element in C.

More Answers (0)

Categories

Find more on Signal Integrity Kits for Industry Standards in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!