Why am I getting an error "vectors must be the same length"

1 次查看(过去 30 天)
I am trying to call an anonymous function to graph, one graph using 1 resolution, the other using .01 resolution. I keep getting a "vectors must be the same length" error when running.
f=@(x) ((exp(x)).*(sin(x)))./((x.^2)+1);
x = 3:1:7; x1 = 3:.01:7;
plot(x,f(x),x1,f(x))

采纳的回答

Thorsten
Thorsten 2015-9-10
编辑:Thorsten 2015-9-10
It's a typo; your last x must be x1
plot(x, f(x), x1, f(x1))

更多回答(2 个)

James Tursa
James Tursa 2015-9-10
plot(x,f(x),x1,f(x1)); % Changed last f(x) to f(x1)

Michael
Michael 2015-9-10
Is there a typing error? Did u mean plot(x,f(x),x1,f(x1<---))?
Just use
figure(1);
plot(x,f(x));
figure(2);
plot(x1,f(x1));

类别

Help CenterFile Exchange 中查找有关 Line Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by