フィルターのクリア

How to record all the values from my previous loop?

2 ビュー (過去 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)
  1 件のコメント
AppleNg
AppleNg 2023 年 4 月 9 日
Thank you so much!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops 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