Nested for loop plots

조회 수: 1 (최근 30일)
Justin Hayes
Justin Hayes 2020년 5월 8일
댓글: Justin Hayes 2020년 5월 9일
time_range = 1:10
for k_cotton = 0.04:0.02:0.08
for t = 1:1:length(time_range)
insert multiple variables as a function of (t)
code.....
Tskin_forearm(t) = k_cotton .* t .* variables(t)
code......
end
figure(1)
plot(time_range, Tskin_forearm)
grid on
xlabel('Time (seconds)')
ylabel('Temperature (Kelvin)')
legend('T skin .04','T skin .06','T skin .08')
title('Temperature of forearm over time')
end
Im shortening this code to make this easier. I am indexing within a nested loop. When the code goes to run k_cotton = 0.06 and then k_cottton = 0.08, it seems that the code is using indexed values from the previous k_cotton value. How do I fix this? In the end, I would like to plot the three Tskin_forearm values over time as a function of the three different k_cotton values.

채택된 답변

darova
darova 2020년 5월 9일
Use this solution
  댓글 수: 4
Justin Hayes
Justin Hayes 2020년 5월 9일
from the graph you can see as the nest loop goes from k_cotton = 0.04 to k_cotton = 0.06 to 0.08, the value of the Temperature at t = 0 begins at a lower and lower value. All three temperatures should start at the same value, and then deviate from there. I believe this is because values such as Tskin_forearm are being carried over from k_cotton = 0.04 to calculate Tskin_forearm for k_cotton =0.06
Justin Hayes
Justin Hayes 2020년 5월 9일
I need to be able to reset the Tskin_forearm values when a new k_cotton value loop begins. Ex) when the nest loop switches from graphing k_cotton =0.04 to k_cotton =0.06, I do not want the loop to use prior calculated Tskin_forearm numbers

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

추가 답변 (0개)

카테고리

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