Matrix Multiplication column and vector

조회 수: 3 (최근 30일)
Alexandra
Alexandra 2015년 8월 3일
댓글: Alexandra 2015년 8월 3일
Hi,
I am trying to solve this problem:
A is 1 column of 100k results; B is a vector of 10 weights; I need a matrix of 10 columns and 100k rows:
[(result line 1)*W1 (result line 1)*W2 (result line 2)*W1 (result line 2)*W2 ...
Thank you very much,
  댓글 수: 1
Torsten
Torsten 2015년 8월 3일
I don't understand the logic behind
[(result line 1)*W1 (result line 1)*W2 (result line 2)*W1 (result line 2)*W2 ...
Could you explain ?
Best wishes
Torsten.

댓글을 달려면 로그인하십시오.

채택된 답변

Andrei Bobrov
Andrei Bobrov 2015년 8월 3일
A is 1 column of 100k results; W is a vector of 10 weights;
A(:)*W(:).'
  댓글 수: 1
Alexandra
Alexandra 2015년 8월 3일
Thanks, it worked! Could you help me on just one more operation?
So now I have a 100k*10 matrix. I also have a 10*1 matrix of target values for each weighted result.
So, i am trying to evaluate how many values in the first column of 100k*10 are bellow the first value in the vector, and by how much. Next, how many values in the second column are bellow the second number and by how much. Therefore I am trying to get a 10*1 vector of number of cases bellow target for each target and a 100k*10 matrix of the difference to target. I written this: A = zeros(size(100k*10 matrix)); n = numel(A); for k=1:n if 100k*10 matrix < OBJECTIVO A = OBJECTIVO - 100k*10 matrix; else A = 0; end end PA = (n - sum(A == 0))/n; But get the same error Error using < Matrix dimensions must agree.
Thanks a lot

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Lukas Bystricky
Lukas Bystricky 2015년 8월 3일
Try
B*A
where A is a row vector and B is a column vector (you may need to transpose them to get them in this form). That will give a matrix with length(B) rows and length(A) columns.
  댓글 수: 2
Alexandra
Alexandra 2015년 8월 3일
I tried: Error using * Inner matrix dimensions must agree.
Lukas Bystricky
Lukas Bystricky 2015년 8월 3일
편집: Lukas Bystricky 2015년 8월 3일
The first vector has to be a column vector and the second a row vector, otherwise the multiplication isn't defined. You can turn a row vector into a column vector (or vice versa) by using
A = A'
for example.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by