My plot function seems to not work

William Hidevik on 10 Sep 2022
Latest activity Edit by Christopher Stapels on 12 Sep 2022

Hi guys,
I'm very new to matlab, so this might a rookie mistake. However, it seems that I have messed up some important part with the plot function. The program does not give my any kind of error messages, but still does not plot anything. What can I have done wrong and how do I fix this?
Best regards
My code:
close all
for t = -2:0.1:3
if (t<0 || t>1)
xvalue = 0;
end
if (t<= 1 && t>= 0)
xvalue = exp(2*t+1);
end
yvalue = -1*(xvalue) + exp(1);
hold on
figure(1);
plot(t, yvalue);
hold off
end
grid on;
Christopher Stapels
Christopher Stapels on 12 Sep 2022 (Edited on 12 Sep 2022)
try
scatter(t, yvalue);
You are making a whole bunch of one point plots each time you go through the loop (thus they are blank for plot). I would consider building an array in your loop and then plotting all the data at once, at the end.

Tags