CREATING A LOOP FROM DATA

Hi, i am wondering if anyone can help me create a loop for this data? I have typed it all out individually but was wondering how i go about creating a loop to condense it all down? Thanks in advance
A1= (B(:,1) - C(1))/ D(1)
A2 = (B(:,2) - C(2)) / D(2)
A3 = (B(:,3) - C(3)) / D(3)
A4 = (B(:,4) - C(4)) / D(4)
A5 = (B(:,5) - C(5)) / D(5)
A6 = (B(:,6) - C(6)) / D(6)
A7 = (B(:,7) - C(7)) / D(7)
A8 = (B(:,8) - C(8)) / D(8)
A9 = (B(:,9) - C(9)) / D(9)
A10 = (B(:,10) - C(10)) / D(10)
A11 = (B(:,11) - C(11)) / D(11)
A12 = (B(:,12) - C(12)) / D(12)
A13 = (B(:,13) - C(13)) / D(13)
A14 = (B(:,14) - C(14)) / D(14)
A15 = (B(:,15) - C(15)) / D(15)
A16 = (B(:,16) - C(16)) / D(16)
A17 = (B(:,17) - C(17)) / D(17)
A18 = (B(:,18) - C(18)) / D(18)
A19 = (B(:,19) - C(19)) / D(19)
A20 = (B(:,20) - C(20)) / D(20)
A21 = (B(:,21) - C(21)) / D(21)
A22 = (B(:,22) - C(22)) / D(22)

Risposte (1)

Monika Jaskolka
Monika Jaskolka il 16 Nov 2021
n = 22;
B = rand(10,n);
C = rand(n,1);
D = rand(n,1);
A = zeros(size(B));
for i = 1:n
A(:,i) = (B(:,i) - C(i))/ D(i);
end

2 Commenti

scientist121
scientist121 il 16 Nov 2021
Thanks for your reply, can i ask why you put B=rand(10,n)...where did the 10 come from?
I chose it arbitrarily because you didn't provide your data. You can change it to suit your needs.

Accedi per commentare.

Categorie

Scopri di più su Loops and Conditional Statements in Centro assistenza e File Exchange

Prodotti

Release

R2021b

Tag

Richiesto:

il 16 Nov 2021

Commentato:

il 16 Nov 2021

Community Treasure Hunt

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

Start Hunting!

Translated by