Help vectorizing calculation that accesses multiple entries in the input array and the previous element of the output array
古いコメントを表示
I'm wondering if this can be vectorized. I'm accessing two entries in the input array along with the previous entry in the output array.
v and T are a vectors of floats.
[Edit: I left out some complexity and I'm not sure if the answer given can still be applied. I've updated the code below with the full expression.]
out = zeros(length(v), 1);
out(1) = 1;
for i = 2:length(v)
out(i) = out(i - 1) * (v(i) / v(i - 1)) * (T(i) / T(i - 1));
end
2 件のコメント
Jan
2021 年 3 月 22 日
Note: Avoid the square brackets around the counter in FOR loops. They can impede the JIT acceleration. Prefer:
for i = 2:length(v)
Marcus Rademacher
2021 年 3 月 22 日
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Multidimensional Arrays についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!