for loop to use iteration and time

조회 수: 11 (최근 30일)
Murat Piri
Murat Piri 2021년 1월 24일
답변: Gaurav Garg 2021년 1월 27일
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
dpb
dpb 2021년 1월 24일
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 2021년 1월 25일
편집: Murat Piri 2021년 1월 25일
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

댓글을 달려면 로그인하십시오.

답변 (1개)

Gaurav Garg
Gaurav Garg 2021년 1월 27일
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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by