How to use the dot product within a loop to multiply a series of rows?!

조회 수: 5 (최근 30일)
I currently have two matrices.
- V = (1*3) matrix
- coordNORMALS = (18766*3) matrix.
I would like to take the dot product of the two such that:
- C = dot ( V, coordNORMALS)
I understand that to take the dot product the size of the two matrices must be equal, however I would like to find C for each row, i.e get 18766 values of C
C = dot ( V, coordNORMALS (1 , : )) all the way to C = dot ( V, coordNORMALS ( end , : ))
I have tried to use a loop in the following format but end up in an infinite loop:
for i=1:length(coordNORMALS)
C(i) = dot(V,coordNORMALS(i,:))
end
end
If anyone knows how to help, please reply
Many Thanks Josh

채택된 답변

Gareth Thomas
Gareth Thomas 2014년 3월 24일
V = rand(1,3)
C = rand(13,3)
dot(V,C(1,:))
dot(V,C(2,:))
for i = 1:length(C)
d(i) = dot(V,C(i,:));
end
Does this not work?
  댓글 수: 1
Joshua Otter
Joshua Otter 2014년 3월 24일
It works fine, just me being an idiot. I had the answers coming up in the command window which took ages to load so I thought I was stuck in an infinite loop. Thanks Gareth.

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

추가 답변 (1개)

James Tursa
James Tursa 2014년 3월 25일
A direct matrix multiply is likely to be faster than using dot. E.g., assuming the variables are real:
C = coordNORMALS * V.';

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by