Can someone please explain why my function wont plot correctly
古いコメントを表示
clear all
t=0:10;
y=-2:0.5:2
fig1=0.001*sin((2*t)+(pi/2));
plot (fig1), grid on
回答 (2 件)
Dyuman Joshi
2023 年 9 月 10 日
編集済み: Dyuman Joshi
2023 年 9 月 10 日
You need atleast 2 sets of values to plot a graph.
I assume you want to plot fig1 against t
t=0:10;
fig1=0.001*sin((2*t)+(pi/2));
plot(t, fig1)
grid on
fun = @(t) 0.001*sin((2*t)+(pi/2));
fplot(fun,[0 10])
If this is not what you want, please specify what you want to plot.
2 件のコメント
Daniel
2023 年 9 月 10 日
Dyuman Joshi
2023 年 9 月 19 日
@Daniel, if this answer solved your problem, please consider accepting it.
You'd need to take a bit small step size for t to make your plot look like a sine wave:
clear all
dt=0.1;
t=0:dt:10;
fig1=0.001*sin((2*t)+(pi/2));
figure(1)
plot(t, fig1, 'ro--'), grid on
xlabel('t')
ylabel('y(t)')
%% Alt. way is:
y=@(t)0.001*sin((2*t)+(pi/2));
N = 200; % Number of points
t = linspace(0, 10, N);
figure(2)
plot(t, y(t), 'kd--'), grid on
xlabel('t')
ylabel('y(t)')
カテゴリ
ヘルプ センター および File Exchange で 2-D and 3-D Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!




