Can anyone help me with the error?

1 visualizzazione (ultimi 30 giorni)
Gaurav Srivastava
Gaurav Srivastava il 31 Mag 2019
Modificato: Rik il 31 Mag 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)

Risposta accettata

Rik
Rik il 31 Mag 2019
Modificato: Rik il 31 Mag 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

Più risposte (0)

Categorie

Scopri di più su 2-D and 3-D Plots in Help Center e File Exchange

Tag

Prodotti


Release

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by