I want to subtract two different arrays from each other. how can ı do?

18 ビュー (過去 30 日間)
studentmatlaber
studentmatlaber 2021 年 4 月 22 日
コメント済み: Rik 2021 年 4 月 23 日
I have two TV series. An array consists of 1 column and 5 rows. My B array consists of 50 columns and 5 rows. What I want here is to subtract the value of an array in row 1 column 1 from all elements of array B in row 1. And he continues this process in turn. I tried this code for this, but it doesn't work correctly. I will be glad if you help me.
for i = 1: 5
C = B (i, :) - A (i, 1);
end
  1 件のコメント
Rik
Rik 2021 年 4 月 23 日
Backup:
I want to subtract two different arrays from each other. how can ı do?
I have two TV series. An array consists of 1 column and 5 rows. My B array consists of 50 columns and 5 rows. What I want here is to subtract the value of an array in row 1 column 1 from all elements of array B in row 1. And he continues this process in turn. I tried this code for this, but it doesn't work correctly. I will be glad if you help me.
for i = 1: 5
C = B (i, :) - A (i, 1);
end

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

回答 (1 件)

Walter Roberson
Walter Roberson 2021 年 4 月 22 日
A = randi(9, 5, 1)
A = 5×1
8 3 2 9 8
B = randi(9, 5, 10)
B = 5×10
7 8 2 5 8 9 9 3 4 3 9 9 9 5 3 6 2 2 6 1 4 1 5 9 2 4 4 5 4 9 6 9 1 9 7 2 8 4 4 9 7 1 2 1 7 2 5 4 3 3
B - A
ans = 5×10
-1 0 -6 -3 0 1 1 -5 -4 -5 6 6 6 2 0 3 -1 -1 3 -2 2 -1 3 7 0 2 2 3 2 7 -3 0 -8 0 -2 -7 -1 -5 -5 0 -1 -7 -6 -7 -1 -6 -3 -4 -5 -5

カテゴリ

Help Center および File ExchangeOperators and Elementary Operations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by