How to record all the values from my previous loop?

조회 수: 1 (최근 30일)
AppleNg
AppleNg 2023년 4월 7일
댓글: AppleNg 2023년 4월 9일
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)

채택된 답변

KALYAN ACHARJYA
KALYAN ACHARJYA 2023년 4월 7일
편집: KALYAN ACHARJYA 2023년 4월 7일
% 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)

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by