Can someone please explain why my function wont plot correctly

clear all
t=0:10;
y=-2:0.5:2
y = 1×9
-2.0000 -1.5000 -1.0000 -0.5000 0 0.5000 1.0000 1.5000 2.0000
fig1=0.001*sin((2*t)+(pi/2));
plot (fig1), grid on

답변 (2개)

Dyuman Joshi
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
You can also plot a smooth graph for the same relation via fplot -
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

thank you thats what i needed
@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에 대해 자세히 알아보기

태그

질문:

2023년 9월 10일

댓글:

2023년 9월 19일

Community Treasure Hunt

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

Start Hunting!

Translated by