How to I do sum my result value to a new result value, progressively? In a for loop

1 回表示 (過去 30 日間)
Carlos Puente
Carlos Puente 2021 年 11 月 28 日
編集済み: Adam Danz 2021 年 11 月 29 日
function c_595(~,~,~,~,~,~,~,~)
clear,clc
rho = 4000;
c = 500;
k = 10;
L = 20;
T1 = 0;
T2 = 100;
q_gen = 2*10^7;
dt = 5;
Fo = (k*dt)/(rho*c*(0.01)^2);
gen = (q_gen*dt)/(rho*c);
n = 8;
T = zeros(1,n)';
for p = 1:n
T(p) = (Fo*((T1+273.15)+(T2+273.15)) + (323.15)*(1-2*(Fo)) + gen) - 273.15;
end
T
I get a matrix with the value of T, but I want to get a matrix with the fisrt value of T, then that value + second value, and so on. I can't find a way to do it.
  1 件のコメント
Ive J
Ive J 2021 年 11 月 28 日
Your question is not clear. Please give an example for expected vector for T. Also your loop doesn't make any sense, all elements of T are the same (what's the use of counter p within this loop?)

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

回答 (1 件)

Adam Danz
Adam Danz 2021 年 11 月 28 日
編集済み: Adam Danz 2021 年 11 月 29 日
It sounds like you're describing a cumulative sum which does not need to be done within a loop.
t = [100;100;100;100]
t = 4×1
100 100 100 100
ts = cumsum(t)
ts = 4×1
100 200 300 400
If this is not what you're looking for, please elaborate or provide an explicit example.

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by