for loop to use iteration and time
2 次查看(过去 30 天)
显示 更早的评论
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
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?
回答(1 个)
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
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!