フィルターのクリア

How to vectorize the following code?

3 ビュー (過去 30 日間)
Jordan Tryggvesson
Jordan Tryggvesson 2021 年 5 月 10 日
コメント済み: Jordan Tryggvesson 2021 年 5 月 10 日
I have an nx1 array f and a 3xm array g. I want to carry out the following insertion, where I pick index pairs from the first two rows of g and values from the last row of g:
for int i = 1:m
f(g(1:2,i)) = g(3,i);
end
How can I vectorize the above code? The simple
f(g(1:2,:)) = g(3,:)
does not work and returns the following error
Unable to perform assignment because the left and right sides have a different
number of elements.
Any suggestions?

採用された回答

Walter Roberson
Walter Roberson 2021 年 5 月 10 日
f(g(1:2,:)) = g([3 3], :);
  3 件のコメント
Walter Roberson
Walter Roberson 2021 年 5 月 10 日
Looks okay. Another way would be
f(g(1:2,:)) = kron([1;1], g(3,:).*g(4,:));
Jordan Tryggvesson
Jordan Tryggvesson 2021 年 5 月 10 日
Alright, thanks for the help!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by