フィルターのクリア

How to muliply non equal vectors with slicing?

1 回表示 (過去 30 日間)
Kalasagarreddi Kottakota
Kalasagarreddi Kottakota 2021 年 11 月 24 日
回答済み: KSSV 2021 年 11 月 24 日
A = 1:12;
B = 1:4;
I am looking for a function that performs multiplication as follows:
  1. Matrix B has 4 elements and matrix A has 12 elements. I want to multiply B with A, in a sequence of multiplying B with A(1:4), and next B with A(5:8), and so on.
  2. I want to perform this complete operation in one instance with some matlab function or vectorization without any loops involved
Could some one help me in this regard?

回答 (1 件)

KSSV
KSSV 2021 年 11 月 24 日
A = 1:12;
B = 1:4;
A = reshape(A,4,[])' ;
iwant = A.*B
iwant = 3×4
1 4 9 16 5 12 21 32 9 20 33 48

カテゴリ

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

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by