How to record all the values from my previous loop?

7 views (last 30 days)
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
Radius = Diameter/2 % 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)
y = vpa(solve(sqrt((x-Radius)^2+(y1-0)^2) == Radius),5)
y1 = sum(y)
end
Total_reinforcement = vpa(y/1000*((Bar_Diameter/2)/1000)^2 * Total_Bar_No* Steel/1000 *pi*2.5,4)

Accepted Answer

KALYAN ACHARJYA
KALYAN ACHARJYA on 7 Apr 2023
Edited: KALYAN ACHARJYA on 7 Apr 2023
% Input
Diameter = 9100; % mm
Radius = Diameter/2; % 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);
y(i)= vpa(solve(sqrt((x(i)-Radius)^2+(y1-0)^2) == Radius),5);
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)

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!