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

51 visualizzazioni (ultimi 30 giorni)
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 Commento
Rik
Rik il 23 Apr 2021
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

Accedi per commentare.

Risposte (1)

Walter Roberson
Walter Roberson il 22 Apr 2021
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

Categorie

Scopri di più su Multidimensional Arrays in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by