# How to record all the values from my previous loop?

8 vues (au cours des 30 derniers jours)
AppleNg le 7 Avr 2023
Commenté : AppleNg le 9 Avr 2023
Hi, guys! I want to retrieve all the data from my previous loop in x & y values. I want to sum up all the y values to calculate the final answer in the equation: Total_reinforcement.
This script has a problem. It only considered the final y value and put it into the equation: Total_reinforcement.
I want to sum all the y values into Total_reinforcement. How can I do that? Thank you guys. I have been hard struggle in this script.
% Circular + Retangular Shape
% Reinforcement quantity
clear
% Input
Diameter = 9100 % mm
Cover = 75 % mm
Bar_Diameter = 40 % mm
Spacing = 150 % mm
Steel = 7850 % kg
% Output
R = Radius - Cover - Bar_Diameter/2
Bar_No = fix(R/Spacing)
Total_Bar_No = Bar_No * 2 + 1
x_1 = Cover + Bar_Diameter/2
x_range = 1:R;
for i = x_1:Spacing:length(x_range)
x = x_range(i)
syms y1
assume(y1 >= 0)
y1 = sum(y)
end
Total_reinforcement = vpa(y/1000*((Bar_Diameter/2)/1000)^2 * Total_Bar_No* Steel/1000 *pi*2.5,4)
##### 0 commentairesAfficher -2 commentaires plus anciensMasquer -2 commentaires plus anciens

Connectez-vous pour commenter.

### Réponse acceptée

KALYAN ACHARJYA le 7 Avr 2023
Modifié(e) : KALYAN ACHARJYA le 7 Avr 2023
% Input
Diameter = 9100; % mm
Cover = 75; % mm
Bar_Diameter = 40; % mm
Spacing = 150; % mm
Steel = 7850; % kg
% Output
R = Radius - Cover - Bar_Diameter/2;
Bar_No = fix(R/Spacing);
Total_Bar_No = Bar_No * 2 + 1;
x_1 = Cover + Bar_Diameter/2;
x_range = 1:R;
x=zeros(1,length(x_range));
y=zeros(1,length(x_range));
for i = x_1:Spacing:length(x_range)
x(i)= x_range(i); % x array can be avoided
syms y1
assume(y1 >= 0);
y1 = sum(y(i));
end
% Sum all y, then use to get the Total_reinforcement
Total_reinforcement = vpa(sum(y)/1000*((Bar_Diameter/2)/1000)^2 * Total_Bar_No* Steel/1000 *pi*2.5,4)
Total_reinforcement =
156.4
If you're looking for Total_Reinforcement in the individual y's, then the sum of all total reinforcement in the latter, that can be done as well.
Total_reinforcement(i)= vpa(sum(y(i))/1000*((Bar_Diameter/2)/1000)^2 * Total_Bar_No* Steel/1000 *pi*2.5,4)
within loop, later sum(Total_reinforcement)
##### 1 commentaireAfficher -1 commentaires plus anciensMasquer -1 commentaires plus anciens
AppleNg le 9 Avr 2023
Thank you so much!

Connectez-vous pour commenter.

### Catégories

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

R2021b

### Community Treasure Hunt

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

Start Hunting!

Translated by