add numbers to an array correspondingly

3 ビュー (過去 30 日間)
Omar Almahallawy
Omar Almahallawy 2019 年 6 月 15 日
回答済み: Image Analyst 2019 年 6 月 15 日
A= [ 6 10 14 ]
B= 0.0152 0.0134 0.0120
0.0121 0.0109 0.0100
0.0089 0.0084 0.0079
0.0058 0.0058 0.0058
answer= 6.0152 10.0134 14.0120
6.0121 10.0109 14.0100
6.0089 10.0084 14.0079
6.0058 10.0058 14.0058
i want to add first column from A with the first column from B and so on

回答 (2 件)

Star Strider
Star Strider 2019 年 6 月 15 日
Use bsxfun:
A = [ 6 10 14 ];
B = [0.0152 0.0134 0.0120
0.0121 0.0109 0.0100
0.0089 0.0084 0.0079
0.0058 0.0058 0.0058];
answer = bsxfun(@plus, A, B)
producing:
answer =
6.0152 10.0134 14.0120
6.0121 10.0109 14.0100
6.0089 10.0084 14.0079
6.0058 10.0058 14.0058

Image Analyst
Image Analyst 2019 年 6 月 15 日
If you have a fairly recent version of MATLAB, that does automatic expansion, you can simply do
output = B + A

カテゴリ

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