How to create a loop for varying the values of A, B & C according to months?

1 vue (au cours des 30 derniers jours)
WASIM ASHRAF
WASIM ASHRAF le 25 Juil 2021
Commenté : WASIM ASHRAF le 26 Juil 2021
% FOR the month of January from ASHRAE-1972 MODEL
% A,B,C are constant and depends on month value.
A = 1164;
B = 0.149;
C = 0.109;
theta_z = 30;
I_bn = A*exp(-B/cosd(theta_z));
I_b = I_bn*cosd(theta_z);
I_d = C*I_bn;
% for Feb month the values of A, B & C are-
A = 1095;
B = 0.135;
C = 0.119;
% How to create a loop which can calculate I_bn, I_b & I_d as per each month?

Réponse acceptée

VBBV
VBBV le 25 Juil 2021
A, B and C are not constants, they are actually variables.
  1. Define, vectors for each of the parameters, A, B and C
  2. Then use a for loop to each of the parameters, A, B and C
  3. Store the values into I_bn, I_b & I_d vectors for each of the months as below
months = 1:12; % assuming 12 in year !!
A = rand(1,12)*1500; % values for each month
B = rand(1,12);
C = rand(1,12);
theta_z = 30;
for i = 1: length(months)
I_bn(i) = A(i)*exp(-B(i)/cosd(theta_z));
I_b(i) = I_bn*cosd(theta_z);
I_d(i) = C(i)*I_bn;
end
  2 commentaires
VBBV
VBBV le 25 Juil 2021
Modifié(e) : VBBV le 25 Juil 2021
You could also actually avoid a for loop and use logical indexing to calculate I_bn, I_b & I_d vectors for each of the months
WASIM ASHRAF
WASIM ASHRAF le 26 Juil 2021
Thanks, I understood it very nicely.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by