Can anyone help me with the error?

2 views (last 30 days)
Gaurav Srivastava
Gaurav Srivastava on 31 May 2019
Edited: Rik on 31 May 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)

Accepted Answer

Rik
Rik on 31 May 2019
Edited: Rik on 31 May 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

More Answers (0)

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Tags

Products


Release

R2017b

Community Treasure Hunt

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

Start Hunting!