Vectorized array operation which depends on previous array value
古いコメントを表示
Hi,
There is any way of making this operation vectorized?
a = ones(1000,1);
b = rand(1000,1);
c = rand(1000,1);
for i=2:1000
a(i) = b(i) + a(i-1) .* c(i);
end
I really appreciate your help, Many thanks, Dylan
1 件のコメント
Matt J
2018 年 1 月 23 日
I think you would have to use either Simulink or a MEX routine.
採用された回答
その他の回答 (1 件)
Torsten
2018 年 1 月 23 日
a(2:end)=b(2:end)+a(1:end-1).*c(2:end);
Best wishes
Torsten.
2 件のコメント
Walter Roberson
2018 年 1 月 23 日
This would copy out the original a values and use them in the computation. The original code uses the a values that were just set in the previous iteration.
Dylan Marques
2018 年 1 月 23 日
カテゴリ
ヘルプ センター および File Exchange で Operators and Elementary Operations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!