Multiplicación de varias columnas por una matriz

조회 수: 2 (최근 30일)
Isabel Aldana Benavides
Isabel Aldana Benavides 2020년 4월 23일
댓글: Isabel Aldana Benavides 2020년 4월 23일
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

채택된 답변

Geoff Hayes
Geoff Hayes 2020년 4월 23일
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.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Signal Integrity Kits for Industry Standards에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by