필터 지우기
필터 지우기

Plotting and storing results from a while loop.

조회 수: 1 (최근 30일)
Louis Lowagie
Louis Lowagie 2016년 4월 29일
편집: Renato Agurto 2016년 4월 29일
Hello,
i am currently working on a thermal model. My function is the heatflux-function and this calculates the temperature in one step. The idea is to use a while-loop to calculate the consecutive temperatures after multiple passes. This means the heatflux function uses the T_end from the previous loop to calculate the heatflux for the next loop. However, when i program this loop it doesn't seem to respond as wanted. I would also like to store the outputs of the function (Q, T_end, delta_T) and be able to plot after the loop has completed. The heatflux function works with the given inputs. Can somebody give me some useful tips on how to approach this problem?
Thanks in advance.
My current code is posted below.
if true
%
while i<N
r = r_initial - i*p/tan(angle);
[Q , delta_T, T_end ] = heatflux(v, p, r , angle, T, laserpower);
T = T_end + delta_T;
T(i) = T_end + delta_T;
i = i+1;
end
plot (T)
end

답변 (1개)

Renato Agurto
Renato Agurto 2016년 4월 29일
I think you already have the answer in your code. The problem is that you are overwriting T in the following line
T = T_end + delta_T;
.
%You need to give the inicial value to T
T(1) = ...
%or
T(i-1) = ...
if true
%
while i<N
r = r_initial - i*p/tan(angle);
[Q(i) , delta_T(i), T_end(i) ] = heatflux(v, p, r , angle, T(i-1), laserpower);
T(i) = T_end(i) + delta_T(i);
i = i+1;
end
plot (T)
end
  댓글 수: 2
Louis Lowagie
Louis Lowagie 2016년 4월 29일
This doesn't work. I get an error.
Renato Agurto
Renato Agurto 2016년 4월 29일
편집: Renato Agurto 2016년 4월 29일
What value does i have when getting this error? i should be 1 or higher. Actually 2 or higher in case you are using T(i-1)

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

카테고리

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