Undefined Variable for plot

11 views (last 30 days)
C
C on 14 Nov 2014
Commented: Ali Mohamed on 13 Feb 2022
Hello, I am am trying to plot the equation "sum" but im not sure what to do with the undefined variable t
clear, clc
for k = 0:9
n = (2*k + 1);
sum = (4/(pi*n))*sin(n*t)
end
plot(sum)
  2 Comments
Geoff Hayes
Geoff Hayes on 14 Nov 2014
Also, try not to name your local variables after built-in functions with the same name. Rename your sum variable to total instead.

Sign in to comment.

Answers (1)

Ali Mohamed
Ali Mohamed on 13 Feb 2022
Make a random vector for t make sure it has 10 elements in order to plot sum vs t
use for example t= 0:1:9
or maybe use linespace
  1 Comment
Ali Mohamed
Ali Mohamed on 13 Feb 2022
t= 0:9;
for k = 0:9
n = (2*k + 1);
sum = (4/(pi*n))*sin(n*t)
end

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!