Store results from loop.

1 回表示 (過去 30 日間)
Isai Fernandez
Isai Fernandez 2018 年 4 月 16 日
回答済み: Birdman 2018 年 4 月 16 日
I am practicing to write in Matlab.
I have an issue, I want to store all "S" results from a loop calculation. I tried to do it from other answers, but I can't get it.
This is the code:
As1= = 510; fy=420; h = 650; d = 590; Es = 200000;
fc = 21; As2 = 520; b = 350; beta1 = .85;
c = [0.0001:.1:1]*h;
for c = c
es = (d-c)./c*ecu
fs = min( fy, max( -fy, es.*Es) )
F = fs.*As/1000
Cc = beta1*fc*b*.85*c/1000
S = sum(F)-Cc
S(c,1) %%Trying to store all "S" calculated values in a column matrix
end
elementS = find(S>0,1)
neededc = c(1,elementS)

回答 (1 件)

Birdman
Birdman 2018 年 4 月 16 日

I believe you need to read about for loop and subscripting. Try this:

As1=510; fy=420; h = 650; d = 590; Es = 200000; 
fc = 21; As2 = 520; b = 350; beta1 = .85;ecu=1;%couldn't find ecu, randomly given
c = [0.0001:.1:1]*h;
for i=1:numel(c)
    F = min(fy,max( -fy,((d-c(i))./c(i)*ecu).*Es)).*As1/1000;
    Cc = beta1*fc*b*.85*c(i)/1000;
    S(:,i) = sum(F)-Cc;
end
elementS = find(S>0,1)
neededc = c(1,elementS)

カテゴリ

Help Center および File ExchangeOperators and Elementary Operations についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by