MATLAB: Plotting nested for loop

for looploop nest

time_range = 1:10;
y = zeros(1,10);
hold on
for x = 0.5:0.5:1
for t = 1:1:length(time_range)
x = 0.5;
y(t) = x .* t;
end
plot(time_range,y)
grid on
xlabel('Time (seconds)')
ylabel('J/s')
legend('Q skin')
title('Q over time')
end
I would like to have 2 separate graphs. One graph for x = 0.5 and one graph for x = 1. When I run the code I only get one graph. How do I fix this?

Best Answer

Remove this line
x = 0.5;
from the for-loop.
Correct code is
time_range = 1:10;
y = zeros(1,10);
hold on
for x = 0.5:0.5:1
for t = 1:1:length(time_range)
y(t) = x .* t;
end
plot(time_range,y)
grid on
xlabel('Time (seconds)')
ylabel('J/s')
legend('Q skin')
title('Q over time')
end