フィルターのクリア

Add vector items one-by-one to array

2 ビュー (過去 30 日間)
MLP
MLP 2022 年 6 月 4 日
編集済み: Voss 2022 年 6 月 4 日
Hello, let's say I have a vector
v = [10 20 30]
and I have an array
a = [11 12 13 14]
How would I go about to get the following result without having to write a for loop?
out = [11 12 13 14 21 22 23 24 31 32 33 34 41 42 43 44]
Here I am adding each element of v to each element to a, and storing them in out.
I tried
out = [a a+(10:10:30)]
which is obviously wrong.

採用された回答

Voss
Voss 2022 年 6 月 4 日
編集済み: Voss 2022 年 6 月 4 日
v = [10 20 30];
a = [11 12 13 14];
out = reshape(a.'+[0 v],1,[])
out = 1×16
11 12 13 14 21 22 23 24 31 32 33 34 41 42 43 44

その他の回答 (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