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 个评论

Please provide an example data. Sometimes the size (of the data) does matter.

请先登录,再进行评论。

 采纳的回答

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

3 个评论

for some reason this didnt work for me
I tried and it gave the same result as your code, like Fangjun said you should provide one example for us to test.
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