Dear all,
I am trying to vectorize the following statement:
u=zeros(n,2,2);
v=zeros(N);
w=zeros(n,2,2);
for j=1:n
u(j,1,1)=v(j)*w(j,1,1);
end
The vectorized version:
j=1:n
u(j,1,1)=v(j)*w(j,1,1);
But I got the error message:
Inner matrix dimensions must agree
because N>n.
Would you please suggest a way to resolve this problem? Thank you.

 채택된 답변

Kelly Kearney
Kelly Kearney 2013년 12월 2일

0 개 추천

u(j,1,1) = v(j) .* w(j,1,1);
The .* means element-by-element multiplication; otherwise, it attempts matrix multiplication.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

질문:

2013년 12월 2일

답변:

2013년 12월 2일

Community Treasure Hunt

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

Start Hunting!

Translated by