help understanding simple Vectorization

Hi,
I am new to vectorization and would appreciate if someone could help me vectorize the following;
for i = 1: length(A)
idx = A(i,1);
C(i) = A(i,1)*B(idx);
end

댓글 수: 1

Fangjun Jiang
Fangjun Jiang 2011년 8월 6일
Please provide an example data. Sometimes the size (of the data) does matter.

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

 채택된 답변

Fangjun Jiang
Fangjun Jiang 2011년 8월 6일

0 개 추천

C=A(:,1).*B(A(:,1))

댓글 수: 3

salamay
salamay 2011년 8월 6일
for some reason this didnt work for me
Paulo Silva
Paulo Silva 2011년 8월 6일
I tried and it gave the same result as your code, like Fangjun said you should provide one example for us to test.
salamay
salamay 2011년 8월 6일
im sorry it works
my syntax was wrong
example
A = [1 2; 1 3; 1 6; 2 2; 2 6; 3 9]
B = [2 5 9]

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Simulink에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by