for loop to use iteration and time

2 visualizaciones (últimos 30 días)
Murat Piri
Murat Piri el 24 de En. de 2021
Respondida: Gaurav Garg el 27 de En. de 2021
Hello all,
I'm quite new user of Matlab.
My question is;
T_pu=ones(iter,1)*293;
T_pu_time=ones((total_t/delta_t)+1,1)*293;
delta_t=1;
total_t=36000;
iter=5;
for t=1:delta_t:total_t
for i=1:iter
x_tpu(i)=(T_e-T_pu(i))/(2));
y_tpu(i)=(T_x-T_pu(i))/(5);
T_pu(i+1)= T_pu(i)+(x_tpu(i)+y_tpu(i)))*(t/2);
if i==iter
T_pu(iter)=T_pu_time(t);
end
end
end
Shortly, I want to start from time=1 and T_pu with iteration (5 times), 5th iteration is equal of my first T_pu_time(t) matrix element, then it will continue with t=2 and 5 iteration .....
Can you please help me or share with me any example how can I solve this issue?
  2 comentarios
dpb
dpb el 24 de En. de 2021
Not clear what you're trying to do, sorry...
T_pu=ones(iter,1)*293;
T_pu_time=ones((total_t/delta_t)+1,1)*293;
delta_t=1;
total_t=36000;
iter=5;
in the above, however, you used iter to preallocate two arrays, but didn't define it until afterwards...so whatever iter was the last time you ran the code before would have just been the left over value.
What's the *293 intended to do in those two statements? Why would you preallocate arrays containing the value 293 which is what that does?
Murat Piri
Murat Piri el 25 de En. de 2021
Editada: Murat Piri el 25 de En. de 2021
Hi,
>Let me explain it,
I'm trying to solve T_pu by iteration numbers and 5th iteration is 1st input of T_pu_time, then t increase to 2 (2nd value). after 5 iteration this value will be 2nd value of T_pu_time.
5th element of T_pu == 1st element of T_pu_time
10th element of T_pu == 2nd element of T_pu_time
....
....
....
>iter mean iteration that I want to calculate the T_pu,
>293 is 293K=20C, I use 293 to set all values of T_pu equal to 293
>I was using iter to set max matrix size of T_pu

Iniciar sesión para comentar.

Respuestas (1)

Gaurav Garg
Gaurav Garg el 27 de En. de 2021
Hi Murat,
In order to assign 5th element of T_pu to 1st element of T_pu_time, 10th element of T_pu == 2nd element of T_pu_time and so on..., you can follow the code segment given below -
for i=1:n
T_pu_time(i) = T_pu(i*5);
end

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by