Can anyone help me with the error?

1 Ansicht (letzte 30 Tage)
Gaurav Srivastava
Gaurav Srivastava am 31 Mai 2019
Bearbeitet: Rik am 31 Mai 2019
edit by Rik (code originally posted as image):
clc
clear
disp(' Question Number 2')
x=0:1:10;
y=40./(1+((x-4).^2) + 5*sin((20*x)/pi));
fplot(y,x)

Akzeptierte Antwort

Rik
Rik am 31 Mai 2019
Bearbeitet: Rik am 31 Mai 2019
You aren't plotting a function, but a vector. Replace fplot by plot, or replace your input by a function. Actually, doing both will teach you a valuable lesson about aliasing.
It is always a good idea to read the documentation carefully when you are getting unexpected results or errors.
Here is a code example of both options (using subplot to show them in one figure):
clc
%clear %no need to use clear
disp(' Question Number 2')
x=0:1:10;
f=@(x) 40./(1+((x-4).^2) + 5*sin((20*x)/pi));
y=f(x);
figure(1),clf(1)%only use clf in debugging
subplot(1,2,1)
plot(x,y)
ylim([-35 35])%ensure same view for both plots
subplot(1,2,2)
fplot(f,[min(x) max(x)])
ylim([-35 35])%ensure same view for both plots

Weitere Antworten (0)

Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange

Tags

Produkte


Version

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by