Multiplying part of vector with another vector repeatedly without for loop

1 回表示 (過去 30 日間)
I have a very long vector A, and I want to take each 10 elements of it and multiply it element-by-element (.*) by another vector has length 10 called "carrier" without using for loop because it takes very long time. This portion of the code did the required but it takes a very long time so is there any way to do it without for loop?
s = [];
for k2 = 1:length(A)
s = [s sequence(1+(k2-1)*10:k2*10).*carrier];
end

採用された回答

Kaushik Lakshminarasimhan
Kaushik Lakshminarasimhan 2017 年 11 月 12 日
Try using repmat:
s = sequence(:).*repmat(carrier(:),N,1); % N is the no.of 10-element segments in 'sequence'
  1 件のコメント
Osama Hussein
Osama Hussein 2017 年 11 月 12 日
Thank you very much. Just instead of N, it should be the length of vector A.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by