Undefined Variable for plot

2 ビュー (過去 30 日間)
C
C 2014 年 11 月 14 日
コメント済み: Ali Mohamed 2022 年 2 月 13 日
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 件のコメント
Andrew Reibold
Andrew Reibold 2014 年 11 月 14 日
What is t.
Is it suppose to be time? For what period? Do you know what you are trying to plot? Are you trying to create multiple plots in the same figure, using time as an independant variable (my hypothesis)? Do you have two independant variables with k also being one?
We need the full story to be able to help you
Geoff Hayes
Geoff Hayes 2014 年 11 月 14 日
Also, try not to name your local variables after built-in functions with the same name. Rename your sum variable to total instead.

サインインしてコメントする。

回答 (1 件)

Ali Mohamed
Ali Mohamed 2022 年 2 月 13 日
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 件のコメント
Ali Mohamed
Ali Mohamed 2022 年 2 月 13 日
t= 0:9;
for k = 0:9
n = (2*k + 1);
sum = (4/(pi*n))*sin(n*t)
end

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by